-1

I am getting syntax errors on my while loop and switch statement which I have not gotten before when using this syntax.

I have tried using various different formats for my loop and my switch statement. It still provides a syntax error The error message reads "Syntax error on token(s), misplaced construct(s)" and "Syntax error on token "case", assert expected".

   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();
   }
  }
}
Andronicus
  • 25,419
  • 17
  • 47
  • 88
  • What was the compiler error? The compiler issues errors for a reason. – David R Tribble Apr 01 '19 at 18:09
  • These are all the errors i received, i got an error for all of my cases. File: C:\Users\danwr\Downloads\Lab7_1.java [line: 7] Error: Syntax error on token(s), misplaced construct(s) File: C:\Users\danwr\Downloads\Lab7_1.java [line: 9] Error: Syntax error on token "case", assert expected File: C:\Users\danwr\Downloads\Lab7_1.java [line: 12] Error: Syntax error on token "case", assert expected File: C:\Users\danwr\Downloads\Lab7_1.java [line: 15] Error: Syntax error on token "case", assert expected – Dan wright Apr 01 '19 at 20:08

1 Answers1

3

There is no such thing in java: while(1<x<=14). You can only compare two numbers at a time, so you would have to write: while(1 < x && x <= 14) instead.

Andronicus
  • 25,419
  • 17
  • 47
  • 88