public class Segitiga {
public static void main (String[] arg){
int n = 5,j,k;
String tampil = "";
for(int i=1;i<=n;i+=2){ // jika pengen 1 2 3 ganti aja i++, tapi kalo 1 3 5 biarin pake i+=2
for(j=n;j>i;j--){
tampil += " ";
}
for(k=1;k<=i;k++){
tampil += "0 ";
}
tampil += "\n";
}
System.out.print(tampil);
}
}
Tidak ada komentar:
Posting Komentar