Program Membuat “Zig Zag” dalam Java

/*

* demo zigzag
*
* Maksum Rois Adin Saf/ 09.11.2680
*/
public class ZigZag {

public static void main (String[] args) {

int i,j,atas=0;
System.out.println(“– Membuat Gambar ZigZag –“);

System.out.print(” Lebar Zigzag : “);
String lebarStr = System.console().readLine();
int lebar = Integer.parseInt(lebarStr);

System.out.print(” Panjang Zigzag : “);
String panjangStr = System.console().readLine();
int panjang = Integer.parseInt(panjangStr);

System.out.print(“M “);
atas+=2;
while(atas<lebar){

if (atas+3<=lebar) {

System.out.print(“MMM “);

atas += 4;

} else if (atas+2<=lebar) {

System.out.print(“MM “);

atas += 3;

} else {

System.out.print(“M “);
atas+=2;

}

} System.out.println();
for(i=1; i<=panjang-2; i++) {

j=1;
while(j<=lebar) {

System.out.print(“M”);

j++;

if (j <= lebar) {

System.out.print(” “);

j++;

}

} System.out.println();

}

atas=0;
while(atas<=lebar){

if (atas+3<=lebar) {

System.out.print(“MMM “);

atas += 4;

} else if (atas+2<=lebar) {

System.out.print(“MM “);

atas += 3;

} else {

System.out.print(“M “);
atas+=2;

}

} System.out.println();

}

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

%d blogger menyukai ini: