有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

swing JOptionPane和读取整数初学者Java

我目前有一个代码,可以读取用户在一行中输入的月份、日期和年份(用空格分隔)。这是代码

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工作,我在书中的那一章对我的这个具体用法没有帮助。任何帮助都会很好。谢谢大家


共 (0) 个答案