-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathpattern.java
144 lines (123 loc) · 2.66 KB
/
pattern.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import java.util.*;
public class pattern{
public static void main(String args[]){
/*solid rectangle
int n=4;
int m=5;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
System.out.print("*");
}
System.out.println();
}*/
/*hollow rectangle rows(i)=outer loops column(j)=inner loops
int n=4;
int m=5;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
//cell(i,j)
if(i==1||j==1||i==n||j==m){
System.out.print("*");
}
else{
System.out.print(" ");
}
}
System.out.println();
}*/
/*half pyramid
int n=4;
for(int i=1; i<=n; i++){
for(int j=1; j<=i; j++){
System.out.print("*");
}
System.out.println();
}*/
/*inverted half reverse pyramid
int n=4;
for(int i=n; i>=1; i--){
for(int j=1; j<=i; j++){
System.out.print("*");
}
System.out.println();
}*/
/*inverted half reverse pyramid with rotated by 180 degree..
int n=4;
for(int i=1; i<=n; i++){
//inner loop = space print..
for(int j=1; j<=n-i; j++){
System.out.print(" ");
}
//inner loop =star print
for(int j=1; j<=i; j++){
System.out.print("*");
}
System.out.println();
}*/
/*pyramid with rotated by 180 degree..
int n=4;
for(int i=n; i>=1; i--){
//inner loop = space print..
for(int j=1; j<=n-i; j++){
System.out.print(" ");
}
//inner loop =star print
for(int j=1; j<=i; j++){
System.out.print("*");
}
System.out.println();
}*/
/*half pyramid with numbers
int n=5;
for(int i=1; i<=n; i++){
for(int j=1; j<=i; j++){
System.out.print(j+ " ");
}
System.out.println();
}*/
/*inverted half pyramid with numbers
int n=5;
for(int i=n; i>=1; i--){
for(int j=1; j<=i; j++){
System.out.print(j+ " ");
}
System.out.println();
}*/
/*floyd's triangle
int n=5;
int number=1;
for(int i=1; i<=n; i++){
for(int j=1; j<=i; j++){
System.out.print(number + " ");
number ++ ;//number = number +1
}
System.out.println();
}*/
/*0-1 triangle
int n=5;
for(int i=1; i<=n; i++){
for(int j=1; j<=i; j++){
int sum=i+j;
if(sum%2==0) //even
System.out.print("1"+ " ");
else{ //odd
System.out.print("0"+ " ");
}
}
System.out.println();
}*/
//1-0 triangle
int n=5;
for(int i=1; i<=n; i++){
for(int j=1; j<=i; j++){
int sum=i+j;
if(sum%2==0) //even
System.out.print("0"+ " ");
else{ //odd
System.out.print("1"+ " ");
}
}
System.out.println();
}
}
}