import java.util.Scanner;
public class switchexercise{
// 创建主类
public static void main (String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("=========转换==========");
System.out.println("请输入一个小写字母(a/b/c/d/e):");
char zimu = scanner.next().charAt(0);
switch(zimu){
case 'a':{
System.out.println("A");
break;}
case 'b':{
System.out.println("B");
break;}
case 'c':{
System.out.println("C");
break;}
case 'd':{
System.out.println("D");
break;}
case 'e':{
System.out.println("E");
break;}
default:{
System.out.println("other");
}
}
System.out.println("=========成绩==========");
//分析:成绩[60-100] / 60 == 1;
//[0-60) / 60 == 0;
System.out.println("请输入成绩:");
int youscore = scanner.nextInt();
int score = (int)(youscore / 60);
switch(score){
case 1:{
System.out.println("合格");
break;
}
case 0:{
System.out.println("不合格");
break;
}
default :{
System.out.println("您输入的成绩有误,请重新输入.[0-100]");
}
}
System.out.println("=========月份==========");
System.out.println("请输入月份:");
int month = scanner.nextInt();
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:
case 11:{System.out.println("秋季");
break;}
case 12:
case 1:
case 2:{System.out.println("冬季");
break;}
}
}
}
输出:
学习自b站韩顺平老师发布的java30天速成-p119、p120