-
Notifications
You must be signed in to change notification settings - Fork 0
/
HallowSquare_283.java
39 lines (35 loc) · 1.13 KB
/
HallowSquare_283.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
import java.util.*;
public class HallowSquare_283 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
if (a <= b) System.out.println("Wrong order!");
else if ((a - b) % 2 != 0) System.out.println("Wrong difference!");
else {
for (int i = 0; i < (a - b) / 2; i++) {
printStar(a);
System.out.println();
}
for (int i = 0; i < b; i++) {
printStar((a - b) / 2);
printSpaces();
printStar((a - b) / 2);
System.out.println();
}
for (int i = 0; i < (a - b) / 2; i++) {
printStar(a);
System.out.println();
}
}
}
private static void printStar(int x) {
for (int j = 0; j < x; j++) {
if (j != x - 1) System.out.print("* ");
else System.out.print("*");
}
}
private static void printSpaces() {
for (int i = 0; i < 7; i++) System.out.print(" ");
}
}