这个问题在这里已有答案:
我在while循环和switch语句中遇到语法错误,这是我在使用这种语法之前没有得过的。
我尝试过为循环和switch语句使用各种不同的格式。它仍然提供语法错误错误消息显示“令牌上的语法错误,错位的构造”和“令牌上的语法错误”案例“,断言预期”。
Scanner input = new Scanner(System.in);
System.out.println("Please enter a number between 1 and 14. I will
then tell you the playing card assosiated with it.");
int x = intput.nextInt();
while(1<x<=14){
Switch(x){
case 1:
System.out.println("Your card is an Ace.");
break;
case 2:
System.out.println("Your card is a two.");
break;
case 3:
System.out.println("Your card is a three.");
break;
case 4:
System.out.println("Your card is a four.");
break;
case 5:
System.out.println("Your card is a five.");
break;
case 6:
System.out.println("Your card is a six.");
break;
case 7:
System.out.println("Your card is a seven.");
break;
case 8:
System.out.println("Your card is an eight.");
break;
case 9:
System.out.println("Your card is a nine.");
break;
case 10:
System.out.println("Your card is a ten.");
break;
case 11:
System.out.println("Your card is an Ace.");
break;
case 12:
System.out.println("Your card is a Jack.");
break;
case 13:
System.out.println("Your card is a Queen.");
break;
case 14:
System.out.println("Your card is a King.");
break;
}
System.out.println("Please enter a number between 1 and 14. I will
then tell you the playing card assosiated with it.");
x = input.nextInt();
}
}
}
java中没有这样的东西:while(1<x<=14)
。你一次只能比较两个数字,所以你必须写:while(1 < x && x <= 14)
。