-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEx 1.java
More file actions
36 lines (34 loc) · 1.02 KB
/
Ex 1.java
File metadata and controls
36 lines (34 loc) · 1.02 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int a= sc.nextInt();
int b= sc.nextInt();
if (b >= a) {
System.out.print("Wrong order!");
}
else if ((a - b) % 2 != 0) {
System.out.print("Wrong difference!");
}
else{
char star = '*', space = ' ';
int dif = (a - b) / 2;
for(int i = 0; i < a; i++){
for(int j = 0; j < a; j++){
if(i >= dif && (i + dif) < a && j >= dif && (j + dif) < a){
System.out.print(space);
}
else{
System.out.print(star);
}
if(j + 1 < a){
System.out.print(' ');
}
}
if(i + 1 < a){
System.out.print('\n');
}
}
}
}
}