1import java.util.Scanner;
2public class Edureka
3{
4
5public static void main(String[] args)
6{
7Scanner sc = new Scanner(System.in);
8
9System.out.println("Enter the number of rows: ");
10
11int rows = sc.nextInt();
12
13for (int i = 1; i <= rows; i++) { for (int j = i; j >= 1; j--)
14 {
15 System.out.print(j+" ");
16 }
17
18 System.out.println();
19}
20sc.close();
21}
22}
23
1public class Main {
2
3 public static void main(String[] args) {
4 int rows = 5, k = 0, count = 0, count1 = 0;
5
6 for (int i = 1; i <= rows; ++i) {
7 for (int space = 1; space <= rows - i; ++space) {
8 System.out.print(" ");
9 ++count;
10 }
11
12 while (k != 2 * i - 1) {
13 if (count <= rows - 1) {
14 System.out.print((i + k) + " ");
15 ++count;
16 } else {
17 ++count1;
18 System.out.print((i + k - 2 * count1) + " ");
19 }
20
21 ++k;
22 }
23 count1 = count = k = 0;
24
25 System.out.println();
26 }
27 }
28}
1// Java implementation to print the
2// following pyramid pattern
3public class Pyramid_Pattern {
4
5 // function to print the following pyramid
6 // pattern
7 static void printPattern(int n)
8 {
9 int j, k = 0;
10
11 // loop to decide the row number
12 for (int i = 1; i <= n; i++) {
13
14 // if row number is odd
15 if (i % 2 != 0) {
16
17 // print numbers with the '*'
18 // sign in increasing order
19 for (j = k + 1; j < k + i; j++)
20 System.out.print(j + "*");
21 System.out.println(j++);
22
23 // update value of 'k'
24 k = j;
25 }
26
27 // if row number is even
28 else {
29
30 // update value of 'k'
31 k = k + i - 1;
32
33 // print numbers with the '*' in
34 // decreasing order
35 for (j = k; j > k - i + 1; j--)
36 System.out.print(j + "*");
37 System.out.println(j);
38 }
39 }
40 }
41
42 // Driver program to test above
43public static void main(String args[])
44 {
45 int n = 5;
46 printPattern(n);
47 }
48}