-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathTriangleNumber.java
More file actions
42 lines (39 loc) · 929 Bytes
/
TriangleNumber.java
File metadata and controls
42 lines (39 loc) · 929 Bytes
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
package pattern2;
import java.util.Scanner;
/*
for N = 4 print the pattern
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
*/
public class TriangleNumber {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int i = 1;
while (i <= n) {
int spaces = 1;
while (spaces <= n - i) {
System.out.print("\t");
spaces++;
}
int temp = i;
int j = 1;
while (j <= i) {
System.out.print(temp + "\t");
j++;
temp++;
}
temp--;
int k = 1;
while (k < i) {
temp--;
System.out.print(temp + "\t");
k++;
}
System.out.println();
i++;
}
}
}