print pyramid triangle in java
Pattern based exercises are
a better way to understand nested loops in Java. There are many pattern based exercises
and one of them is printing Pyramid pattern code as shown below:
// program to print
Pyramid pattern in java
class Pyramid1{
public
static void main(String rgs[]){
int
i, j,k;
for(i=1;i<=5;i++){
for(j=5;
j>=i;j--){
System.out.print(" ");
}
for(k=1;k<=i;k++){
System.out.print("*
");
}
System.out.println();
}
}
}
output:
0 comments: