Java program to print numbers in pyramid vice

Program

```package com.candidjava;

import java.util.Scanner;

public class PatternNumberPyramidArrow
{
public static void main(String args[])
{
int i, j, n;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the values ");
n = sc.nextInt();
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
System.out.print(" " + j);
System.out.print("\n");
}
for (i = n - 1; i >= 1; i--)
{
for (j = 1; j <= i; j++)
System.out.print(" " + j);
System.out.print("\n");
}
}

}```

Output

Enter the values

5

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

1 2 3 4

1 2 3

1 2

1

Program

```package com.candidjava;

import java.util.Scanner;

public class PatternNumberPyramidRev
{

public static void main(String args[])
{
int i, j, k, n, a;

Scanner sc = new Scanner(System.in);
System.out.println("Enter the n values");
n = sc.nextInt();
a = n;
for (i = 1; i <= n; i++)
{
for (j = a; j > 1; j--)
{
System.out.print(" ");
}
for (k = i; k != 0; k--)
{
System.out.print(k);

}
a--;

for (int l = 2; l <= i; l++)
{
System.out.print(l);

}
System.out.println();
}

}

}
```

Output

Enter the n values

5

1

212

32123

4321234

543212345

Related Post