-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathIsoscelesTriangle.java
More file actions
41 lines (38 loc) · 921 Bytes
/
IsoscelesTriangle.java
File metadata and controls
41 lines (38 loc) · 921 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
package pattern2;
import java.util.Scanner;
/*
for N = 4 print the pattern
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
*/
public class IsoscelesTriangle {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int i = 1;
while (i <= n) {
int j = 1;
// number of spaces to be printed
while (j <= n - i) {
System.out.print("\t");
j++;
}
// increasing number
j = 1;
while (j <= i) {
System.out.print(j + "\t");
j++;
}
// decreasing number
j = 1;
while (j <= i - 1) {
System.out.print(j + "\t");
j++;
}
System.out.println();
i++;
}
}
}