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