본문 바로가기
Tech/Java

[Java] 별찍기문제

by 소라소라잉 2019. 8. 5.

Q.1
*****
*****
*****
*****
*****


Q.2
*
  *
   *
    *
     *


Q.3
    *
   * 
  * 

 *
*


Q.4
*     *
 *   *
   *

 *   *
*     *


Q.5
*
**
***
****
*****


Q.6
*****
****
***
**
*


Q.7
*****
******
*******
********
*********


Q.8
*
***
*****
*******
*********


Q.9
*****
*****
*****
** **
*****


Q.10
*****
 ***
  *
 ***
*****

 

public static void main(String[] args) {

    System.out.println("Q.1");
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= 5; j++) {
            System.out.print("*");
        }
        System.out.println();
    }

    System.out.println("Q.2");
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= 5; j++) {
            if (i == j)
                System.out.print("*");
            else
                System.out.print(" ");
        }
        System.out.println();
    }

    System.out.println("Q.3");
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= 5; j++) {
            if (i + j == 6)
                System.out.print("*");
            else
                System.out.print(" ");
        }
        System.out.println();
    }

    System.out.println("Q.4");
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= 5; j++) {
            if (i + j == 6 || i == j)
                System.out.print("*");
            else
                System.out.print(" ");
        }
        System.out.println();
    }

    System.out.println("Q.5");
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= 5; j++) {
            if (i >= j)
                System.out.print("*");
            else
                System.out.print(" ");
        }
        System.out.println();
    }

    System.out.println("Q.6");
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= 5; j++) {
            if (i + j <= 6)
                System.out.print("*");
            else
                System.out.print(" ");
        }
        System.out.println();
    }

    System.out.println("Q.7");
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= i + 4; j++) {
            System.out.print("*");
        }
        System.out.println();
    }

    System.out.println("Q.8");
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= i + 4; j++) {
            if (i + j >= 6)
                System.out.print("*");
            else
                System.out.print(" ");
        }
        System.out.println();
    }

    System.out.println("Q.9");
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= 5; j++) {

            if ((i >= j && i + j <= 6) || (i <= j && i + j >= 6))
                System.out.print("*");
            else
                System.out.print(" ");
        }
        System.out.println();
    }

    System.out.println("Q.10");
    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= 5; j++) {
            if ((i + j <= 6 && j >= i) || (i + j >= 6 && j <= i))
                System.out.print("*");
            else
                System.out.print(" ");
        }
        System.out.println();
    }

}

 

댓글