import javax.swing.*;//Allow JOptionPane
import java.io.*;//Allow input/output
class months//declare class 'months'
{
public static void main(String[] args)//main function
{
String month = JOptionPane.showInputDialog(null, //creates dialog box
"Enter number for month, 1 to 12");//tells user what to do, closes dialog
switch(month)
{
case 1: System.out.println("Jan"); break;
case 2: System.out.println("Feb"); break;
case 3: System.out.println("Mar"); break;
case 4: System.out.println("Apr"); break;
case 5: System.out.println("May"); break;
case 6: System.out.println("Jun"); break;
case 7: System.out.println("Jul"); break;
case 8: System.out.println("Aug"); break;
case 9: System.out.println("Sep"); break;
case 10: System.out.println("Oct"); break;
case 11: System.out.println("Nov"); break;
case 12: System.out.println("Dec"); break;
default: System.out.println("Please Try Again"); break;
}
System.exit(0);//exits system
}
}
im just looking to print out the month name based on a number input via jinputpane. what happens is the switch doesnt work cause joption has to be string, and switch has to be int. sucks. so i need a way to convert string to int, or help using the built in date function in java which i cant figure out for anything.
the only requirement is that i have to use joptionpane.

New Topic/Question
Reply




MultiQuote





|