現在、ユーザーが入力した月、日、年を 1 行で (スペースで区切って) 読み取るコードがあります。これがコードです。
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();
これは正常に動作し、2 番目の部分はメッセージを表示することです。月 * 日 == 年であれば、それは魔法の数であり、そうでない場合は魔法の数ではありません。ダイアログボックスに表示する必要があります。これがそのための私のコードであり、うまく機能しています。
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);
}
私の質問は!! コンソールで動作するように、月、日、年の入力を 1 行に表示するダイアログ ボックスを取得するにはどうすればよいですか。私は DrJava で作業していますが、私が読んでいる本の章は、この特定の用途については役に立ちません。どんな助けでも素晴らしいでしょう。皆さんありがとう!