-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSc2310_ChrisTree.java
More file actions
57 lines (36 loc) · 1.49 KB
/
CSc2310_ChrisTree.java
File metadata and controls
57 lines (36 loc) · 1.49 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.Scanner;
public class ChrisTree {
public static void buildTrees(int a, int b){ //b is number of segments, a is rows of segments
for(int i = 0; i < b*2; i++){ //number of segments per tree
for(int j = 0; j <= a*2; j++){ //rows per segment
if(j%2!=0 && (j+i)%2!=0){ //first part ensures that only odd numbered segments and rows are used
for(int x = a*2+(Math.max(a,b)+2); x > j+i; x-=2){ //ensures that greater of a,b is always used for spacing so that
//you can have a tall skinny tree (a<b) or a short fat tree (a>b)
System.out.print(" "); //and that the trees bottom is 2 spaces from the edge of the page
}
for(int k = 0; k < j+i; k++){ //dots per line
System.out.print("*");
}
if((j+i)%2!=0){ //ensures that only odd numbered sections are shown
System.out.println();
}
}
}
}
System.out.println(" * ");
System.out.println(" * ");
System.out.println(" *******");
}
public static void main(String args[]){
Scanner input = new Scanner(System.in);
System.out.println("This is a program to build Christmas Trees.\n");
System.out.println("How many segments are in your tree?");
int segment = input.nextInt();
System.out.println("How tall is each segment (rows per segment)?");
int tall = input.nextInt();
buildTrees(tall, segment);
if (input != null){
input.close();
}
}
}