Skip to content

Commit d4c7a22

Browse files
committed
Pattern Problem
1 parent 2bbd94b commit d4c7a22

File tree

1 file changed

+41
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)