我在while循环和switch语句中遇到语法错误,并且对为什么感到困惑

时间:2019-04-01 17:09:18

标签: java while-loop switch-statement

我在while循环和switch语句中遇到语法错误,这是使用该语法之前从未得到的。

我已经尝试为循环和switch语句使用各种不同的格式。它仍然提供语法错误 错误消息显示为“令牌语法错误,构造放置错误” 和“令牌“ case”的语法错误,需要断言”。

   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();
   }
  }
}

1 个答案:

答案 0 :(得分:3)

在Java中没有这样的东西:while(1<x<=14)。您一次只能比较两个数字,因此必须写:while(1 < x && x <= 14)