JAVA
190626 switch 문 예제
猫猫
2019. 6. 26. 14:53
반응형
package prj190626;
import java.util.*;
public class Switch_2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int month = 0;
System.out.print("현재 월을 입력하세요");
Scanner scan = new Scanner(System.in);
String tmp = scan.nextLine();
month = Integer.parseInt(tmp);
switch(month) {
case 3:
case 4:
case 5:
System.out.println("봄");
break;
case 6: case 7: case 8:
System.out.println("여름");
break;
case 9: case 10:
System.out.println("가을");
break;
//case 1: case 2: case 11: case 12: //에러를 잡아내려면 이렇게 돌리고, 아니면 default 값을 겨울로 둬서 많은 case 제어하게
default:
System.out.println("겨울");
//System.out.println("1~12 만 입력");
}
}
}
반응형