for문 - 별찍기
class Ex01 { public static void main(String[] args) { System.out.println("별찍기"); for(int i=1; i<=5; i++){ for(int j=1; j<=i; j++){ System.out.print("*"); } System.out.println(" "); } } } 결과 * ** *** **** *****
========================================================================================
[ 거꾸로 찍기 ]
class Ex01 { public static void main(String[] args) { System.out.println("별찍기"); for(int i=5; i>=1; i--){ for(int j=1; j<=i; j++){ System.out.print("*"); } System.out.println(); } } } 결과 ***** **** *** ** * ========================================================================================[ 정사각형 ]
class Ex01 { public static void main(String[] args) { System.out.println("별찍기"); for(int i=0; i<=10; i++){ for(int j=i; j<=10; j++){ System.out.print(" "); } for(int k=0; k<i; k++){ System.out.print(" "+"*"); } System.out.println(); } } } 결과 *
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
========================================================================================
[ 다이아몬드 ] class Ex01 { public static void main(String[] args) { System.out.println("별찍기"); for(int i=0; i<=10; i++){ for(int j=i; j<=10; j++){ System.out.print(" "); } for(int k=0; k<i; k++){ System.out.print(" "+"*"); } System.out.println(); } for(int i=10; i>=0; i--){ for(int j=i; j<=10; j++){ System.out.print(" "); } for(int k=0; k<i; k++){ System.out.print(" "+"*"); } System.out.println(); } } } 결과 *
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*