谁能告诉我如何将“switch-case”用于数字以及扫描仪类,以便从键盘读取的数字应与给定的 switch case 进行比较并打印最终输出?
import java.util.Scanner;
public class Switchcase{
public static void main(String[] args) {
int age;
Scanner bhavya = new Scanner(System.in);
System.out.println("enter your age:");
age = bhavya.nextInt();
switch (age) {
case 1:
System.out.println("you can crawl");
break;
case 2:
System.out.println("you can talk");
break;
case 3:
System.out.println("you can get in trouble");
break;
default:
System.out.println("i dnt know how old you are");
break;
}
}