我目前有讀取用戶輸入一行(用空格分隔)的月份,日期和年份的代碼。這是代碼。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工作,而我所在的這本書的章節並沒有幫助我進行這種具體的使用。任何幫助都會很棒。謝謝大家!
謝謝你給了一些代碼。它似乎在工作,但你可以做一個快速解釋如何。我只需要幫助理解String {} vals = word.split(「\\ s +」)和parseInt方法。 – ShiftyMcGrifty 2013-02-09 01:47:32
@ShiftyMcGrifty我更新了答案,並添加了幾個鏈接,這將給你更多的信息。 – Smit 2013-02-09 01:54:36
非常感謝,我現在正在查看API。看着我的任務,我相信我的教授只是要求輸出對話框,我能夠得到。但學習這將在未來有用。再一次,謝謝! – ShiftyMcGrifty 2013-02-09 01:58:39