forked from ErSKS/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPattern21.java
42 lines (39 loc) · 1.16 KB
/
Pattern21.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
package javapatternsmorning;
/**
*
* @author ErSKS
*/
public class Pattern21 {
public static void p() {
System.out.println("\nPattern21");
final int N = 15, M = N / 2 + 1;
for (int i = 1; i <= N - M; i++) {
for (int j = 1; j <= N; j++) {
if (j <= i || j > N - i) {
if (j % 2 == 1) {
System.out.print("1 ");
} else {
System.out.print("0 ");
}
} else {
System.out.print(" ");
}
}
System.out.println();
}
for (int i = N - M + 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (j <= M - (i - M) || j >= M + (i - M)) {
if (j % 2 == 1) {
System.out.print("1 ");
} else {
System.out.print("0 ");
}
} else {
System.out.print(" ");
}
}
System.out.println();
}
}
}