print pyramid pattern in java. Example 2
If you want print pattern like given below:
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
//program to print pyramid pattern
package pattern_progrm;
public class
Pattern_progrm {
public static void main(String[] args) {
int i,j;
int sum ;
for(i=1;i<=5;i++){
sum=i;
for(j=1;j<=i;j++){
System.out.print("
"+sum);
sum+=5-j;
}
System.out.println();
}
}
output:
0 comments: