My assignment is to ask the user to enter a number 1-12 and you will print out the the name of the month. You MUST use enumerated types to associate the number entered to the name of the month.
This is what I have so far
import java.util.*; public class Assignment4{ enum Month{January, February, March, April, May, June, July, August, September, October, November, December} public static void main(String[]args){ int in=getInput(); for (Month m: Month.values()){ System.out.printf("Month %s = %s\n",in , m); }//end of for }//end of main public static int getInput (){ Scanner input = new Scanner (System.in); System.out.println("Please, enter a number (1-12) of the month you want me to print. "); int in = input.nextInt(); return in; }//end of getInput }//end of class
The problem is no matter what number I put in, it prints out the entire enum. I realize this is because I'm using Month.values() However, anything else I put in errors out. I did read
http://www.javaprogrammingforums.com...use-enums.html
I tried some of the other methods but I guess I'm not entering something correctly