1. Keyword Break

class TugasBreak{
public static void main(String[] args){
int k=5;
System.out.println(“Before while”);
while(k>=0){
System.out.println(“Nilai k: “+i);
if(k==1) break;
i–;
}
System.out.println(“After while”);
}
}

Output :
Before while
Nilai k : 5
Nilai k : 4
Nilai k : 3
Nilai k : 2
Nilai k : 1
After while

2. Keyword Continue

class TugasContinue{
public static void main(String[] args){
int x;
for(n=6;n>0;n–) {
if(n==5) continue;//statement untuk diabaikan
System.out.println(“Nilai n:”+n);
if(n==6) break;
}
}
}

Output:
Nilai n : 6
Nilai n : 4

Nilai n : 3
Nilai n : 2
Nilai n : 1
Nilai n : 0

3. Retrun

class Return {

// static int  panjang, lebar;

public static double persegipanjang (int panjang, int lebar){

luas =  panjang * lebar;

return luas;
}

public static void main(String args[]){

int panjang = 10;
int lebar   = 5;

System.out.println(”Luas : ” + persegipanjang(panjang, lebar));

}
}

Output :

Luas : 50

4. Class
class siswa {

private  static String nama;
private  static String npm;

private static String kelas;

private static String hoby:

public static void main(String args[]){

nama = “Kartika Nur Ramadha” ;

npm = “10107965”;
kelas = “3KA12”;

hobby = “memasak″ ;

System.out.println(”Nama    : ” + nama);

System.out.println(”Npm     : ” + npm);
System.out.println(”Kelas    : ” + kelas);

System.out.println(”Hobby  : ” + hobby);

}

}

Output :

Nama                     : Kartika Nur Ramadha

Npm                      : 10107965

Kelas                     : 3KA12

Hobby                   : memasak

5. Method

class superclass {

int a;

void display_a () {

System.out.println(“a= “ + a);

}

}

class Subclass extends Superclass {

int a;

void display_a () {

System.out.println (“a= “ + a);

}

void set_super_a(int n) {

super.a = n ;

}

void display_super_a () {

super.display_a () ;

}

}

class SuperDemo {

public static void main (String args[]) {

superclass SuperObj = new Superclass () ;

subclass SubObj = new Subclass () ;

superObj.a = 1;

subObj.a = 2;

subObj.set_super_a (3);

superObj.display_a ();

subObj.display_a ();

subObj.display_super_a ();

system.out.println(SubObj.a);

}

}

Output :

a = 1

a = 2

a = 3

2