各位大神,为什么我这个代码输入一,二这样的字符直接跳到default了,输入1,2,3这样的字符是正确的
import java.util.Scanner;
public class Lx{
public static void main(String[] args){
Scanner console = new Scanner(System.in);
System.out.print("请输入星期:");
char day = console.nextLine().charAt(0);
if(isHasAirLine(day)){
System.out.println("有航班");
}else{
System.out.println("没有航班");
}
}
public static boolean isHasAirLine(char day){
boolean[] ch = {false,true,false,true,false,true,false};
int d =parseDay(day);
boolean c = ch[d];
return c;
}
public static int parseDay(char day){
int d = 0;
switch(day){
case'日':
day = 0;
break;
case '一':case '1':
day = 1;
break;
case '二':case '2':
day = 2;
break;
case '三':case '3':
day = 3;
break;
case '四':case '4':
day = 4;
break;
case '五':case '5':
day = 5;
break;
case '六':case '6':
day = 6;
break;
default:
throw new IllegalArgumentException("星期错误");
}
return d;
}
}