-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest068.java
More file actions
86 lines (70 loc) · 1.5 KB
/
Test068.java
File metadata and controls
86 lines (70 loc) · 1.5 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*===================================================================
■■■ 실행 흐름의 컨트롤(제어문) ■■■
- 5장-03.
- 반복문(for문) 실습
===================================================================*/
/*
■ 다중 반복문(반복문의 중첩)을 활용한 별찍기
○ 과제
다음과 같은 내용이 출력될 수 있도록
반복문의 중첩 구문을 작성하여 프로그램을 구현한다.
실행 예) 마름모
★
★★★
★★★★★
★★★★★★★
★★★★★★★★★
★★★★★★★
★★★★★
★★★
★
*/
public class Test068
{
public static void main(String[] args)
{
// 변수 선언
int i, j; //-- i(행), j(열) 인덱스 변수
// 상단 삼각형
for (i = 5; i > 0; i--)
{
for (j = 1; j <= 10; j++)
{
if (j >= i && j <= (10-i))
{
System.out.print("★");
} else {
System.out.print(" ");
}
}
System.out.println(); //-- 개행 출력
}
// 하단 역삼각형
for (i = 2; i<= 5; i++)
{
for (j = 1; j <= 10; j++)
{
if (j >= i && j <= (10-i))
{
System.out.print("★");
} else {
System.out.print(" ");
}
}
System.out.println(); //-- 개행 출력
}
}
}
//실행 결과
/*
★
★★★
★★★★★
★★★★★★★
★★★★★★★★★
★★★★★★★
★★★★★
★★★
★
계속하려면 아무 키나 누르십시오 . . .
*/