Skip to content

Commit afefb05

Browse files
committed
Pattern Problem
1 parent c6f4a0a commit afefb05

File tree

1 file changed

+62
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)