Looping (Perulangan)

1. For dalam Java

package forpkg;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner input= new Scanner(System.in);
int fortari;
System.out.print(“Masukkan Perulangan For = “);
fortari=input.nextInt();
for(int i = 0 ; i<fortari;i++)
{
System.out.print(“\nRakhmawati”);
}
}

}

]

2. While dalam Java

package whilepkg;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner input= new Scanner(System.in);
int i=0;
int whiletari;
System.out.print(“Masukkan Perulangan While = “);
whiletari=input.nextInt();
while(i<whiletari)
{
System.out.print(“\nLestari”);
i++;
}
}

}

 

3. Do While

package do_while;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner input= new Scanner(System.in);
int i=0;
int dowhiletari;
System.out.print(“Masukkan Perulangan DoWhile = “);
dowhiletari=input.nextInt();
do
{
System.out.print(“\nTari”);
i++;
}
while(i<dowhiletari);

}

}

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s