Skip to content

Commit 6d0022d

Browse files
committed
Pattern 24
1 parent 0a28d50 commit 6d0022d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.java.patterns;
2+
import java.util.Scanner;
3+
/*
4+
Write the program to print the following pattern
5+
1
6+
2 2 2
7+
3 3 3 3 3
8+
4 4 4 4 4 4 4
9+
5 5 5 5 5 5 5 5 5
10+
*/
11+
public class Pattern24 {
12+
public static void main(String args[] ) throws Exception {
13+
Scanner scanner = new Scanner(System.in);
14+
int N = Integer.parseInt(scanner.nextLine());
15+
int iSpace = 0;
16+
int k = 0;
17+
for(int i=0;i<N;i++){
18+
for(int j = iSpace;j<N-1;j++)
19+
System.out.print(" ");
20+
for(int j=0;j<=k;j++)
21+
if(j == 0)
22+
System.out.print(i+1);
23+
else
24+
System.out.print(" "+(i+1));
25+
iSpace++;
26+
k+=2;
27+
if(i != N-1)
28+
System.out.println();
29+
}
30+
scanner.close();
31+
}
32+
}
33+
/*
34+
Input
35+
5
36+
Output
37+
1
38+
2 2 2
39+
3 3 3 3 3
40+
4 4 4 4 4 4 4
41+
5 5 5 5 5 5 5 5 5
42+
*/

0 commit comments

Comments
 (0)