在Switch情况下同时接受大写和小写输入是否正确,如我在下面所写,还是还有其他更好的方法。
import java.util.Scanner;
public class SwitchDemo {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter 'IN' or 'OUT': \n");
String c = sc.nextLine();
switch(c) {
case "IN" :
System.out.println("\nWelcome to My PC\n");
break;
case "OUT":
System.out.println("\nGood Bye\n");
break;
case "in" :
System.out.println("\nWelcome to My PC\n");
break;
case "out":
System.out.println("\nGood Bye\n");
break;
default:
System.out.println("\nInvalid input\n");
}
}
}