need some help with my java code. i'm getting incompatible types error. can anyone tell me what's wrong with my code?

import java.io.*;

public class ifelsechain2
{
      public static void main(String[] args)
      throws java.io.IOException
      {

              String string1;
              int num1;
              InputStreamReader isr = new InputStreamReader(System.in);
              BufferedReader     br = new BufferedReader(isr);

              System.out.println("Enter a Grade: ");

              string1 = br.readLine();

              num1 = Integer.parseInt(string1);

               switch(num1){
               case num1 >= 90:
               case num1 <= 100:
               System.out.println("You have an A! :D");
               break;

               case num1 >= 80:
               case num1 <= 89:
               System.out.println("You have a B! :)");
               break;

               case num1 >= 70:
               case num1 <= 79:
               System.out.println("You have a C. -_-");
               break;

               case num1 >= 60:
               case num1 < 69:
               System.out.println("You have a D. :(");
               break;

               case num1 >= 0:
               case num1 <= 59:
               System.out.println("You have a F. :(");
               break;

               default:
               System.out.println("You messed up");

             }
           }
           }

Edited 3 Years Ago by happygeek: fixed formatting

If it were me I would use an if-elseif-else statement rather than switch-case.

import java.io.*;

public class ifelsechain2
{
public static void main(String[] args) throws IOException
{

String string1;
int num1;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);

System.out.println("Enter a Grade: ");

string1 = br.readLine();

num1 = Integer.parseInt(string1);


if (num1 >= 90 && num1 <=100)
{
System.out.println("You have an A! ");
}
else if (num1 >= 80 && num1 <= 89)
{
System.out.println("You have a B! ");
}
else if (num1 >= 70 && num1 <= 79)
{
System.out.println("You have a C. -_-");
}
else if (num1 >= 60 && num1 <= 69)
{
System.out.println("You have a D. ");
}
else if (num1 >= 0 && num1 <= 59)
{
System.out.println("You have a F. ");
}
else
{
System.out.println("You messed up");
}

}
}
This article has been dead for over six months. Start a new discussion instead.