Im a beginner in the coding world. I have been learning Java recently when i came across a speedbump.
First of all heres the code :
import java.util.*;
public class Stuff {
public static void main(String []args); {
Scanner identity = new Scanner(System.in);
String id;
System.out.println("Please Enter Your Name :");
id = identity.next();
Switch (id); {
case "name1":
//some code here....
break;
case "name2":
//some code here....
break;
case "name3":
//some code here....
break;
case "name4":
//some code here....
break;
default :
//some code here....
break;
}
}
}
The error
Error: Orphaned case
case: "name1";
I cant seem to find why this is happening and have googles to no avail.
Edit : Some people have said that I am ending Switch early with the semi colon. But when i add it, i get a new error along with the previous one:
Error: ';' expected
Switch (id) {
^
Switch (id). Take it out. Also,switchneeds to be lower case.switch(id). This ends the switch statement which you did not intend.have googles to no avail.really? the first 5 hits describe exactly your problem :Dcase: "name1";andcase "name1":?public static void main(String []args); {remove this semicolon too