这题不知道怎么回事,刚开始写出来的代码运行结果正确,但是通过不了,现在的代码把switch加入到单独的方法里也通过不了,参考了其他大佬的代码,能通过的只写出来了这个。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
while (n-->0){
String ID = input.next();
int distinct_ID = Integer.parseInt(ID.substring(0,2));
String distinct = new String();
switch (distinct_ID) {
case 33:
distinct = "Zhejiang";
break;
case 11:
distinct= "Beijing";
break;
case 71:
distinct= "Taiwan";
break;
case 81:
distinct= "Hong Kong";
break;
case 82:
distinct= "Macao";
break;
case 54:
distinct= "Tibet";
break;
case 21:
distinct= "Liaoning";
break;
case 31:
distinct= "Shanghai";
break;
}
System.out.println("He/She is from " + distinct + ",and his/her birthday is on " + ID.substring(10, 12) + "," + ID.substring(12, 14) + "," + ID.substring(6, 10) + " based on the table.");
}
}
}