Program java input parameter nonvoid konstruktor


import java.io.*;
class kotak
{
    double panjang;
    double lebar;
    double tinggi;

void cetakvolum(double p,double l,double t)
{
    panjang=p;
    lebar=l;
    tinggi=t;
    double volum;
    volum=panjang*lebar*tinggi;
System.out.print("volum:"+volum);
}
}
public class inputvoidparameter{


public static void main(String[]args)throws IOException
{
    BufferedReader br;
            br = new BufferedReader (new InputStreamReader(System.in));
kotak k=new kotak();
System.out.print("panjang =");
k.panjang=Double.parseDouble(br.readLine());
System.out.print("lebar =");
k.lebar=Double.parseDouble(br.readLine());
System.out.print("tinggi =");
k.tinggi=Double.parseDouble(br.readLine());
k.cetakvolum(k.panjang,k.lebar,k.tinggi);
}


}

import java.io.*;
class kotak
{
    double panjang;
    double lebar;
    double tinggi;

double cetakvolum(double p,double l,double t)
{
    panjang=p;
    lebar=l;
    tinggi=t;
    double volum;
    volum=panjang*lebar*tinggi;
    return volum;

}
}
public class nonvoidparameter{

public static void main(String[]args)throws IOException

{
BufferedReader br;
            br = new BufferedReader (new InputStreamReader(System.in));
kotak k=new kotak();
System.out.print("panjang =");
k.panjang=Double.parseDouble(br.readLine());
System.out.print("lebar =");
k.lebar=Double.parseDouble(br.readLine());
System.out.print("tinggi =");
k.tinggi=Double.parseDouble(br.readLine());
System.out.print("volume="+k.cetakvolum(k.panjang,k.lebar,k.tinggi));
}


}

import java.io.*;
class kotak
{
    double panjang;
    double lebar;
    double tinggi;

kotak()
{
panjang=panjang;
lebar=lebar;
tinggi=tinggi;    
}
    double volum()
    {

    double volum=panjang*lebar*tinggi;
    return volum;

}
}
public class nonvoidkonstruktor{

public static void main(String[]args)throws IOException
{
    BufferedReader br;
            br = new BufferedReader (new InputStreamReader(System.in));
kotak k=new kotak();
System.out.print("panjang =");
k.panjang=Double.parseDouble(br.readLine());
System.out.print("lebar =");
k.lebar=Double.parseDouble(br.readLine());
System.out.print("tinggi =");
k.tinggi=Double.parseDouble(br.readLine());
System.out.print("volum:"+k.volum());


}


}
Previous
Next Post »