public class MyPyramid
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value ");
int n = sc.nextInt();
for (int i = 0; i < n; i++)
{
for (int spc = n - i; spc > 0; spc--)
{
System.out.print(" ");
}
for (int j = 0; j <= i; j++)
{
System.out.print((i + 1) + " ");
}
System.out.println();
}
}
}
Output:
Enter the value
6
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
BUILD SUCCESSFUL (total time: 3 seconds)
|
No comments:
Post a Comment