11-1)
import java.util.Scanner;
public class ex11_1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.print("달을 입력하세요(1~12)>>");
int month = sc.nextInt();
//봄일 경우 (3~5)
if(month==3||month==4||month==5) {
System.out.println("봄");
}
//여름일 경우(6~8)
else if(month==6||month==7||month==8) {
System.out.println("여름");
}
//가을일 경우(9~11)
else if(month==9||month==10||month==11) {
System.out.println("가을");
}
//겨울일 경우(12,1,2)
else if(month==12||month==1||month==2) {
System.out.println("겨울");
}
}
}
11-2)
import java.util.Scanner;
public class ex11_2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.print("달을 입력하세요(1~12)>>");
int month = sc.nextInt();
switch(month) {
//봄 (3~5)
case 3:
case 4:
case 5:
System.out.println("봄");
break;
case 6:
case 7:
case 8:
System.out.println("여름");
break;
case 9:
case 10:
case 11:
System.out.println("가을");
break;
case 12:
case 1:
case 2:
System.out.println("겨울");
break;
}
sc.close();
}
}
결과
달을 입력하세요(1~12)>>1
겨울'명품JAVA프로그래밍 > 2장 자바 기본 프로그래밍' 카테고리의 다른 글
| [명품JAVA프로그래밍] 2장 실습문제 12번 (0) | 2021.12.16 |
|---|---|
| [명품JAVA프로그래밍] 2장 실습문제 10번 (0) | 2021.12.16 |
| [명품JAVA프로그래밍] 2장 실습문제 9번 (0) | 2021.12.16 |
| [명품JAVA프로그래밍] 2장 실습문제 8번 (0) | 2021.12.15 |
| [명품JAVA프로그래밍] 2장 실습문제 7번 (0) | 2021.12.15 |