안녕하세요 엘체프 GG 입니다.

for문을 활용한 별찍기 입니다.


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
package jse_ex_20180123_2;
 
public class Diamond {
    public static void main(String[] args) {
 
        // 상단 정삼각형을 출력하는 반복문
        for (int i = 0; i < 5; i++) {
            for (int j = i; j < 5; j++) {
                System.out.print(" ");
            }
            for (int j = 0; j < i; j++) {
                System.out.print("*");
            }
            for (int j = 0; j < i - 1; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
        // 하단 역삼각형을 출력하는 반복문
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < i; j++) {
                System.out.print(" ");
            }
            for (int j = i; j < 5; j++) {
                System.out.print("*");
            }
            for (int j = i + 1; j < 5; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
 
cs



감사합니다.


'스터디 > JAVA' 카테고리의 다른 글

자바 컬렉션프레임워크(CollectionFramework)_1  (302) 2018.02.22
자바 내부 클래스  (334) 2018.02.22
자바 2차원배열 성적구하기  (6) 2018.01.30
자바 반복문 성적내기  (8) 2018.01.30
자바 구구단 로직  (8) 2018.01.30

+ Recent posts