HomeWorkReview07

"Java Stuty"

Posted by Chungman on March 11, 2021
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
package Review;

public class HomeWorkReview07 {

	public static void main(String[] args) {
		/*
		int space = 4, star = 1;
		for(int i =1; i<=9; i++) {
			for(int j = 1; j <= space; j++) {
				System.out.print("-");
			}
			for(int j = 1; j <= star; j++) {
				System.out.print("*");
			}
			System.out.println();
			
			space += i < 5 ? -1 : 1;
			if(i < 5) {
				star += 2;
			} else {
				star -= 2;
			}
		}
		*/
		
		int n = 1;
		for(int i =1; i<=9; i++) {
			for(int j = 1; j <= 5-n; j++) {
				System.out.print("-");
			}
			for(int j = 1; j <= 2*n-1; j++) {
				System.out.print("*");
			}
			System.out.println();
			
			if(i < 5) {
				n++;
			} else {
				n--;
			}
		}
	}

}