+ 1

Help with switch

if i write: public void PrintMonth ()} String ExtensiveMonth switch (month) { case 1: ExtensiveMonth = "January "; case 2: ExtensiveMonth = " February "; ecc what is extensive month?

19th Dec 2016, 5:57 PM
Mars
Mars - avatar
8 Antworten
+ 2
error
19th Dec 2016, 7:31 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 2
Your code : import java.util.Scanner; public class Program { public static void main(String []args) { Scanner scanner = new Scanner(System.in); System.out.println(" Type in the name of 1 month : "); String month = scanner.nextLine(); switch(month) { case "january": System.out.println("1. \n"); break; case "february": System.out.println("2. \n"); break; case "march": System.out.println("3. \n"); break; case "april": System.out.println("4. \n"); break; case "may": System.out.println("5. \n"); break; case "june": System.out.println("6. \n"); break; case "july": System.out.println("7. \n"); break; case "august": System.out.println("8. \n"); break; case "september": System.out.println("9. \n"); break; case "oktomber": System.out.println("10. \n"); break; case "november": System.out.println("11. \n"); break; case "december": System.out.println("12. \n"); break; } } }
19th Dec 2016, 10:14 PM
Lummos
Lummos - avatar
0
why error?
19th Dec 2016, 7:35 PM
Mars
Mars - avatar
0
You didn't declare string month anywhere. If you say switch(month) that means the string will check if the string month has some (case) value. ExtensiveMonth should be Month for it to work but you don't input month anywhere soo it will most likely print out some random number or 0 ( if you put in print command which you don't have ) Ill write you the code.
19th Dec 2016, 9:53 PM
Lummos
Lummos - avatar
0
thanks!!
20th Dec 2016, 5:18 PM
Mars
Mars - avatar
0
Be free to ask anything. I'll be more than happy to help
20th Dec 2016, 7:14 PM
Lummos
Lummos - avatar
0
Before java you should learn C++. It is more user friendly language
20th Dec 2016, 7:17 PM
Lummos
Lummos - avatar
- 1
I want to develop an android app first, and I've read that java is more easy :/
20th Dec 2016, 8:17 PM
Mars
Mars - avatar