Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Boell Fischer   on Nov 28 In Java Category.

  
Question Answered By: Benjamin Simpson   on Nov 28

You will be getting this error  when you try to use
some expression  or variable next to case:. See
following code for more clarifications.

class SwitchTest
{
static int x=0;
private static int getSomeInt()
{
return 2;
}

public static void main(String str[])
{
switch (getSomeInt()){
//case x: gives same error.
case: 1 // works fine.
System.out.println(1);
break;
case 2:
System.out.println(2);
break;
default:
System.out.println("default");
}


}
}

Share: 

 

This Question has 4 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Java language: switch statement Or get search suggestion and latest updates.


Tagged: