练习一:
使用 switch 把小写类型的 char型转为大写。只转换 a, b, c, d, e. 其它的输 出 “other”。 提示:String word = scan.next(); char c = word.charAt(0); switch©{}
public class test {
public static void main(String[] args) {
char s = 'a';
switch (s) {
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");
break;
}
}
}
练习二:
根据用于指定月份,打印该月份所属的季节。 3,4,5 春季 6,7,8 夏季 9,10,11 秋季 12, 1, 2 冬季
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入月份(1-12):");
int month = sc.nextInt();
switch(month) {
case 3:
case 4:
case 5:
System.out.println("春季");
break;
case 6:
case 7:
case 8:
System.out.println("夏季");
break;
case