Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Switch case In the Java

Tags:

java

I am using Neatbeans 7.0 for Java programming. I have written a Switch case for selection of the program.

switch(menu)
        {
            case 1:
            {
                //stmt
            }
            default:
            {
                //stmt
                return;
            }
        }

I am getting compile time error at switch(menu)

The Error is "strings in switch are not supported in -source 1.6
  (use -source 7 or higher to enable strings in switch)

(Alt-Enter shows hints)" Can any one please help me on this.

like image 298
mayur rahatekar Avatar asked Jan 18 '23 20:01

mayur rahatekar


1 Answers

String cases in switch statements are supported in Java SE 7, but not in previous versions of Java. You need to compile with Java 7.

like image 93
Wayne Avatar answered Jan 31 '23 16:01

Wayne