KH 정보교육원/JAVA

#10일차

bameh 2019. 10. 10. 21:27

#Star, 별찍기(다섯줄, 기본)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class Star
{
    public static void main(String[] agrs)
    {
        int t=1;
        for(int i=0; i<=4; i++){
            for(int j=0; j<4-i; j++){
                System.out.print(" ");
            }
            for(int k=1; k<=t; k++){
                System.out.print("*");
            }
        System.out.println();
        t=t+2;
        }
    }
}

 

#Star2, 별찍기 (다섯줄, 한 칸 공백)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class Star2
{
    public static void main(String[] agrs)
    {
        int t=1;
        for(int i=0; i<=4; i++){
            for(int j=0; j<5-i; j++){
                System.out.print("  ");
            }
            for(int k=1; k<=t; k++){
                System.out.print("* ");
            }
        System.out.println();
        t=t+2;
        }
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

 

#Mystar, 별찍기(다섯 줄, 반대로 출력)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class Mystar
{
    public static void main(String[] agrs)
    {
        int t=1;
        for(int i=0; i<=4; i++){
            for(int j=4; j>=i; j--){
                System.out.print("* ");
            }
            for(int k=1; k<=t; k++){
                System.out.print("  ");
            }
            for(int j=4; j>=i; j--){
                System.out.print("* ");
            }
        System.out.println();
        t=t+2;
        }
    }
}

'KH 정보교육원 > JAVA' 카테고리의 다른 글

#8일차  (0) 2019.10.16
#7일차  (0) 2019.10.16
#6일차  (0) 2019.10.16
#5일차  (0) 2019.10.16
#1일차, 기초 지식  (0) 2019.10.10