Contoh – Contoh PROGRAM :

1. Penggunaan keyword break
* Syntak :
class contohBreak {
public static void main(String args[]) {
int i=0;
do {
i=i+2;
System.out.println(“Saya Belajar JAVA”);
if (i==10) break;  //Penggunaan Break
} while (i<=20);
}
}
* Output :
Saya Belajar Java
Saya Belajar Java
Saya Belajar Java
Saya Belajar Java
Saya Belajar Java
2. Penggunaan keyword continue
*  Syntak :
class contohContinue {
public static void main(String args[]) {
int j=11;
do {
j–;
if (j==7) continue;  //Penggunaan Continue
System.out.println(“No. ” +j);
if (j==5) break;
} while (j>=0);
}
}
*  Output :
No. 10
No. 9
No. 8
No. 6
No. 5
3. Penggunaan keyword return, Penggunaan Class, Penggunaan Method : getter() dan setter()
*  Syntak :
class Balok {   //Penggunaan Class
private double panjang;
private double lebar;
private double tinggi;
public Balok() {
panjang = 0;
lebar = 0;
tinggi = 0;
}
private double hitungvolume (double p, double l, double t) {
return p*l*t;    //Penggunaan Return
}
public void setPanjang(double panjang) {  //Method Setter
this.panjang = panjang;
}
public void setLebar(double lebar) {   //Method Setter
this.lebar = lebar;
}
public void setTinggi(double tinggi) {  //Method Setter
this.tinggi = tinggi;
}
public double getVolume() {  // Method Getter
return hitungvolume(panjang, lebar, tinggi);  //Penggunaan Return
}
public static void main (String[] args) {
Balok b= new Balok();
b.setPanjang(5);   //Penggunaan Method Setter
b.setLebar(4);   //Penggunaan Method Setter
b.setTinggi(10);   //Penggunaan Method Setter
System.out.println(“Volume Balok : “+ b.getVolume());
//Penggunaan Method Getter
}
}
*  Output :
Volume Balok : 200.0
Penggunaan keyword Break
Penggunaan keyword Break
Penggunaan keyword Continue
Penggunaan keyword Continue
Penggunaan keyword Return, Class, Method (Getter & Setter)
Penggunaan keyword Return, Class, Method (Getter & Setter)



Labels : wallpapers Mobile Games car body design Hot Deal
Category:

0 komentar:

Posting Komentar

Search Terms : property home overseas properties property county mobil sedan oto blitz black pimmy ride Exotic Moge MotoGP Transportasi Mewah free-islamic-blogspot-template cute blogger template free-blog-skins-templates new-free-blogger-templates good template blogger template blogger ponsel Download template blogger Free Software Blog Free Blogger template Free Template for BLOGGER Free template sexy Free design Template theme blogspot free free classic bloggerskin download template blog car template website blog gratis daftar html template kumpulan templet Honda SUV car body design office property properties to buy properti new