Contoh Program Java Menggunakan Loop
Contoh loop do while
public class loop_do_while {
public static void main(String args[]){
int x = 10;
do{
System.out.print("Nilai dari x adalah : " + x );
x++;
System.out.print("\n");
}while( x < 20 );
}
}
Contoh loop while
Contoh loop for
Contoh demo for
public class loop_do_while {
public static void main(String args[]){
int x = 10;
do{
System.out.print("Nilai dari x adalah : " + x );
x++;
System.out.print("\n");
}while( x < 20 );
}
}
Hasil Output
Contoh loop while
public class loop_while {
public static void main(String args[]) {
int x = 10;
while( x <= 20 ) {
System.out.print("Nilai dari x adalah " + x );
x++;
System.out.print("\n");
}
}
}
Hasil Output
Contoh loop for
public class loop_for {
public static void main(String args[]) {
System.out.println("Pemakaian loop for");
for(int x = 10; x < 20; x = x+1) {
System.out.print("Nilai dari x adalah " + x );
System.out.print("\n");
}
}
}
Hasil Output
Contoh demo for
class demo_for{
public static void main(String[]args){
for (int i=0; i<=5; i++){
System.out.println("Java");
}
}
}
Hail Output
Comments
Post a Comment