Skip to content

Commit 70f6d2c

Browse files
committed
Pattern 20
1 parent e07e75b commit 70f6d2c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.java.patterns;
2+
import java.util.Scanner;
3+
/*
4+
Write the program to print the following pattern
5+
1
6+
1 2 3
7+
1 2 3 4 5
8+
1 2 3 4 5 6 7
9+
1 2 3 4 5 6 7 8 9
10+
*/
11+
public class Pattern20 {
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+
for(int i=0;i<N;i++){
17+
for(int j = iSpace;j<N-1;j++)
18+
System.out.print(" ");
19+
for(int j=1;j<=2*i+1;j++)
20+
if(j == 1)
21+
System.out.print(j);
22+
else
23+
System.out.print(" "+j);
24+
iSpace++;
25+
if(i != N-1)
26+
System.out.println();
27+
}
28+
scanner.close();
29+
}
30+
}
31+
/*
32+
Input
33+
5
34+
Output
35+
1
36+
1 2 3
37+
1 2 3 4 5
38+
1 2 3 4 5 6 7
39+
1 2 3 4 5 6 7 8 9
40+
*/

0 commit comments

Comments
 (0)