도전 과제 (이중 for 구문)
💡 학습 목표
이중 for 구문 사용하기
이중 for 구문을 활용해서 출력 하시오

0 1 2
0 1 2
0 1 2
package basic.practice;
public class practice_1 {
// code start
public static void main(String[] args) {
for(int j=1; j<4; j++) {
for(int i = 0; i<3; i++) {
System.out.print(i+" ");
}
System.out.println();
}
}
}
별표 찍기 (이중 for 구문을 활용한 코드를 작성해주세요)
*
**
***
****
package basic.practice;
public class practice_2 {
// code start
public static void main(String[] args) {
for(int i=1; i<5; i++) {
for(int j =1; j<i+1; j++) {
System.out.print("*");
}
System.out.println();
}
} // end of main
} // end of class
별표 찍기 (이중 for 구문을 활용한 코드를 작성해주세요)
* - 1 (출력하는거 아님)
*** - 3
***** - 5
******* - 7
********* - 9
package basic.practice;
public class practice_3 {
// code start
public static void main(String[] args) {
for (int i = 1; i < 11; i += 2) {
for (int j = 1; j < i + 1; j++) {
System.out.print("*");
}
System.out.println();
}
} // end of main
} // end of class
별표 찍기 (이중 for 구문을 활용한 코드를 작성해주세요)
****
***
**
*
package basic.practice;
public class practice_4 {
// Code Start
public static void main(String[] args) {
// i는 1, 2, 3, 4 --> 4번 반복
for(int i=1; i<5; i++) {
// j가 1일때 4, j가 2일때 3, j가 3일때 2, j가 4일때 1, 별 찍음
for(int j= 1; j<6-i; j++) {
System.out.print("*");
}
System.out.println();
}
} // end of main
} // end of class
'Java' 카테고리의 다른 글
| 2024.04.15 객체지향 핵심 클래스와 객체 (0) | 2024.04.15 |
|---|---|
| 2024.04.15 Java 객체지향 핵심 OOP(객체지향) (0) | 2024.04.15 |
| 2024.04.12 반복문과 조건문 { 연습문제 } (0) | 2024.04.12 |
| 2024.04.12 break, continue 사용 (0) | 2024.04.12 |
| 2024.04.12 반복문( while ) (0) | 2024.04.12 |