Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Java
String month = sc. nextLine();
switch (month){
case January :
System.out.println("Hello");
break;
case JANUARY:
System.out.println("HelloWorld");
break;
case February:
System.out.println("HelloWorld56");
break;
default:
System.out.println("Hello77655");
}
}
}


What I have tried:

IT shows the error of January, JANUARY and February cannot be resolved to a variable.
Posted
Updated 22-Jul-23 0:51am
v2

I would try with quotes:
Java
String month = sc. nextLine();
switch (month){
case "January" :
System.out.println("Hello");
break;
case "JANUARY" :
System.out.println("HelloWorld");
break;
case "February" :
System.out.println("HelloWorld56");
break;
default:
System.out.println("Hello77655");
}
}
}
 
Share this answer
 
v2
Comments
CPallini 22-Jul-23 6:51am    
5.
Rudra Jul2023 22-Jul-23 6:59am    
Thank you
Patrice T 22-Jul-23 7:29am    
Thank you.
You will never progress unless you make an effort actually to learn the language: Lesson: Language Basics (The Java™ Tutorials > Learning the Java Language)[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900