I currently have code that reads the month, date, and year a user enters in one line (separated by spaces). Here is the code.
Scanner input = new Scanner(System.in);
int day = 0;
int month = 0;
int year = 0;
System.out.printf("enter the month, date, and year(a 2 numbered year). Put a space between the month, day, and year");
month = input.nextInt();
day = input.nextInt();
year = input.nextInt();
This works fine, the second part is to display a message, if month * day == year, then it is a magical number, if not, then it is not a magical number. It has to be displayed in a dialog box. here is my code for that, and it is working just fine.
if((day * month) == year)
{
String message = String.format("%s", "The date you entered is MAGIC!");//If the day * month equals the year, then it is a magic number
JOptionPane.showMessageDialog(null, message);
}
if((day * month) != year)
{
String message = String.format("%s", "The date you entered is NOT MAGIC!");//If the day * month does not equal the year, it is not a magic number
JOptionPane.showMessageDialog(null, message);
}
My question is!! How can I get a dialog box to take the inputs of the month, date, and year in one line the way it works in the console. I'm working in DrJava, and the chapter of the book I'm in doesn't help me with this specific use. Any help would be great. Thanks all!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…