1
package iCanDoIt;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Practice {
public static void main(String[] args) {
String msg=JOptionPane.showInputDialog("Enter a number");
int num1=Integer.parseInt(msg);
String msg2=JOptionPane.showInputDialog("enter another number");
int num2=Integer.parseInt(msg2);
int addition=num1+num2;
String msg3=JOptionPane.showInputDialog("What is" + num1 + "+ " + num2 + " ? ");
int answer=Integer.parseInt(msg3);
while(num1+num2!=answer){
JOptionPane.showMessageDialog(null,"try again");
String answer2=JOptionPane.showInputDialog("wrong. what is " + num1 + "+" + num2 + "?");
int answer3=Integer.parseInt(answer2);
if (num1+num2==answer3)
JOptionPane.showMessageDialog(null,"GREAT job");
}
System.exit(0);
}
}
我是JAVA的初學者。JOptionPane和While循環(用戶輸入添加)
掃描儀輸入看起來很容易理解,但由於某種原因,我使用JOptionPane很困難。
不管怎樣,我的問題是...即使我得到的答案是正確的,我不斷收到「再試一次」
你能告訴我什麼,我做錯了什麼?
@ DaoWen-啊!非常有意義。非常感謝!!!! :) :) :) – user3104903