Menggabunggkan perulangan dengan kondisi if-else menghasilkan output proram segitiga terbalik
import java.util.Scanner;
public class segitiga{
public static void main(String [] args){
Scanner input=new Scanner(System.in);
int batas;
System.out.print("input batas : ");
batas=input.nextInt();
for (int b=batas;b>=1;b--){
for(int c=batas;c>b;c--){
System.out.print(" ");
}
for (int k=1;k<=b;k++){
if(b%2==0)
System.out.print("* ");
else
System.out.print("# ");
}
System.out.println(" ");
}
}
}
01.09
0 komentar:
Posting Komentar