我目前有读取用户在一行中输入的月份、日期和年份的代码(用空格分隔)。这是代码。
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();
这很好,第二部分是显示一条消息,如果月*日==年,那么它是一个神奇的数字,如果不是,那么它不是一个神奇的数字。它必须显示在对话框中。这是我的代码,它工作得很好。
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);
}
我的问题是!!如何获得一个对话框,以在控制台中的工作方式在一行中输入月份、日期和年份。我在 DrJava 中工作,而我所在的书中的章节对我的特定用途没有帮助。任何帮助都会很棒。谢谢大家!