-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask_2
More file actions
38 lines (29 loc) · 1.08 KB
/
Task_2
File metadata and controls
38 lines (29 loc) · 1.08 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
37
38
package TaskTwo;
import java.util.Scanner;
public class TaskTwo {
public static void main(String[] args) {
System.out.println("Input numbers, size of Christmas tree");
Scanner scanner = new Scanner(System.in);
int evenFlag;
int baseSize;
int iteration;
baseSize = scanner.nextInt();
if ((baseSize % 2) == 0) {
evenFlag = 1; // base size is even
iteration = baseSize / 2; // high of tree
} else {
evenFlag = 0; // base size is odd
iteration = (baseSize / 2) + 1; // high of tree
}
for (int i = 0; i < iteration; i++) {
// printing a line
for (int space = 1; (iteration - i) - space > 0; space++) {
System.out.print(" ");
}
for (int wildcards = 0; wildcards <= 2*i + evenFlag; wildcards++) {
System.out.print("*");
}
System.out.println();
}
}
}