-
Notifications
You must be signed in to change notification settings - Fork 2
/
DrawFigure.java
50 lines (31 loc) · 1.15 KB
/
DrawFigure.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
package softuni.exam;
import java.util.Scanner;
public class DrawFigure {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner scan = new Scanner(System.in);
int size = scan.nextInt();
// from top to middle
int dotsCount = 0;
int asteriskCount = size;
for (int i = 0; i < size / 2; i++) {
System.out.print(new String(new char[dotsCount]).replace('\0', '.'));
System.out.print(new String(new char[asteriskCount]).replace('\0', '*'));
System.out.println(new String(new char[dotsCount]).replace('\0', '.'));
dotsCount++;
asteriskCount-=2;
}
// middle
System.out.print(new String(new char[dotsCount]).replace('\0', '.'));
System.out.print('*');
System.out.println(new String(new char[dotsCount]).replace('\0', '.'));
// from middle to bottom
for (int i = 0; i < size / 2; i++) {
dotsCount--;
asteriskCount+=2;
System.out.print(new String(new char[dotsCount]).replace('\0', '.'));
System.out.print(new String(new char[asteriskCount]).replace('\0', '*'));
System.out.println(new String(new char[dotsCount]).replace('\0', '.'));
}
}
}