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(); } } } 결과 *
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
'JAVA 기초' 카테고리의 다른 글
15일차 : 스레드의 동기화 (0) | 2012.08.12 |
---|---|
14일차 : 스레드(Thread) (0) | 2012.08.12 |
13일차 : IO, File클래스, 내부클래스, 객체의 직렬화, 재귀메소드 (0) | 2012.08.12 |
12일차 : IO, 입출력 (0) | 2012.08.12 |
11일차 : 예외처리, IO(InputStream,OutputStream), 패키지 만들기 (0) | 2012.08.12 |