+ 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?
8 Respostas
+ 2
error
+ 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;
}
}
}
0
why error?
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.
0
thanks!!
0
Be free to ask anything. I'll be more than happy to help
0
Before java you should learn C++. It is more user friendly language
- 1
I want to develop an android app first, and I've read that java is more easy :/