Question
My Code is still thowing errors please help 1. error: '(' expected public static void String monthName(int month) { 2. illegal start of type switch
My Code is still thowing errors please help
1.
error: '(' expected public static void String monthName(int month) {
2. illegal start of type switch (month) { ^
3.
import java.text.MessageFormat;
import java.util.Scanner;
public class Assignment3 {
/**
* use a switch statement for this function (no ifs allowed)
* 1=January, 2=February ... 12=December (notice they start with uppercase)
* return "Invalid Month" if not between 1 and 12.
* @return
*/
static String theMonth[] = {
"",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
public static void main(String[] args){
int month = 8;
Scanner sc = new Scanner(System.in);
System.out.print("Enter a Number :");
month = sc.nextInt();
System.out.println(monthName);
}
public static void String monthName(int month) {
String theMonth;
}
switch (month) {
{
int theMonth = monthName.nextInt(1);
String answer = "Invalid Month";
switch (month) {
case 1:
answer = theMonth[1];
break;
case 2:
answer = theMonth[2];
break;
case 3:
answer = theMonth[3];
break;
case 4:
answer = theMonth[4];
break;
case 5:
answer = theMonth[5];
break;
case 6:
answer = theMonth[6];
break;
case 7:
answer = theMonth[7];
break;
case 8:
answer = theMonth[8];
break;
case 9:
answer = theMonth[9];
break;
case 10:
answer = theMonth[10];
break;
case 11:
answer = theMonth[11];
break;
case 12:
answer = theMonth[12];
break;
default:
answer = "Invalid Month";
}
return answer;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started