package com.npp.test;
public class Test {
public static void main(String[] args) {
int n=10;
for(int i=1;i<=n;i++)
for(int j=1;j<=n+1;j++)
System.out.print(i>9?j<=n-i+1?" ":i+" ":j<=n-i+1?" ":i+" ");
}
System.out.println();
}
Instead of writing ternery operator we can write this also
if(i>9)
System.out.print(j<=n-i+1?" ":i+" ");
else
System.out.print(j<=n-i+1?" ":i+" ");
0 Comment to "How to create a pyramid of numbers in java?"
Post a Comment