I need to write a program in java that asks the user to enter the name of a month. Then, using this string and switch statements, I need to output the integer value of that month. For example, if September is entered, it will output 9. There can only be one println() statement for the output string however.
I then need to expand on that program to also tell the user the number of days in the month they've entered. I am supposed to use if-else/else-if statements to do this.
I know this isn't right but this is what I have so far...
import java.util.Scanner; public class Month { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a month: "); monthName = input.nextInt(); switch (monthName) { case "January": month = 1; break; case "February": month = 2; break; case "March": month = 3; break; case "April": month = 4; break; case "May": month = 5; break; case "June": month = 6; break; case "July": month = 7; break; case "August": month = 8; break; case "September": month = 9; break; case "October": month = 10; break; case "November": month = 11; break; case "December": month = 12; break; } System.out.println(month); } }
I was just hoping somebody could point me in the right direction from here...