-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockwise_Triangle_Pattern.java
More file actions
62 lines (54 loc) · 1.54 KB
/
Clockwise_Triangle_Pattern.java
File metadata and controls
62 lines (54 loc) · 1.54 KB
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
import java.util.Scanner;
public class ClockwiseTrianglePattern
{
public static void main(String[] args) {
System.out.print("Enter a Number: ");
int r = new Scanner(System.in).nextInt();
int mt[][] = new int[r][r];
int i=-1, j=-1, ct, val=1, f=1, n=r;
while(n>0){
if(f==1){
ct=n;
while(ct-->0){
i++; j++;
//System.out.println(i+" "+j+" "+val);
mt[i][j]=val++;
}
//System.out.println();
f=2;
n--;
continue;
}
if(f==2){
ct=n;
while(ct-->0){
j--;
//System.out.println(i+ " " +j+" "+val);
mt[i][j]=val++;
}
//System.out.println();
f=3;
n--;
continue;
}
if(f==3){
ct=n;
while(ct-->0){
i--;
//System.out.println(i+" "+j+" "+val);
mt[i][j]=val++;
}
//System.out.println();
f=1;
n--;
continue;
}
}
for(i=0; i<r; i++){
for(j=0; j<=i; j++){
System.out.print(mt[i][j]+" ");
}
System.out.println();
}
}
}