Switch 예제_1)
class SeasonSwitch{
public static void main(String[] args){
int month = 10;
//switch문을 사용하세요
//12~2월은 겨울입니다
//3~5월은 봄입니다
//6~8월은 여름입니다
//9~11월은 가을입니다
//break;를 적절히 사용하세요
class SeasonSwitch{
public static void main(String[] args){
int month = 10 ;
switch(month){
case 12:
case 1:
case 2:
System.out.println("겨울");
break;
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;
}
}
}
Switch 예제_2)
class TaxCul{
public static void main(String[] args){
int price = 3500;
//0~2000원까지는 세금이 5%이다
//2001~5000원까지는 세금이 10%이다
//5001이상은 15%이다
switch(price/1000){
case 0 ~ 4:
default: 5001이상
int price =1000;
if(price > 2000){
System.out.println("5%");
}if(2001<price || price<5000){
System.ou.println("10%);
}if(price<=){
System.ou.println("15%);
}
class TaxCul{
}
public static void main(String[] args){
int price = 3500;
switch(price/1000){
case 0:
case 1:
System.out.println("5%"+(price*0.05));
break;
case 2:
case 3:
case 4:
System.out.println("10%"+(price*0.1));
break;
default
System.out.println("15%"+(price*0.15));
}
}
'JAVA' 카테고리의 다른 글
[Java] 수업 정리 _ 16 (24.11.12) (0) | 2024.11.14 |
---|---|
[Java] 수업 정리 _ 15 (24.11.12) (1) | 2024.11.14 |
[Java] 수업 정리 _ 13 (24.11.12) (0) | 2024.11.14 |
[Java] 수업 정리 _ 12 (24.11.12) (0) | 2024.11.14 |
[Java] 수업 정리 _ 11 (24.11.12) (1) | 2024.11.14 |