新手写代码出错,代码
import javax.swing.JOptionPane;
public class TurtorLoop {
public static void main(String[] args) {
int correctCount=0;
int count=0;
long starttime= System.currentTimeMillis();
String output="";
while(count<10){
int num1=(int)(Math.random()*10);
int num2=(int)(Math.random()*10);
if(num1<num2){
int temp = num1;
num1 = num2;
num2 = temp;
}
String answerString = JOptoinPane.showInputDialog ("What is "+num1+"-"+num2+"?");
int answer= Integer.parseInt(answerString);
String replyString;
if (num1 - nun2 == answer ) {
replyString = "You are correct";
correctCount++;
}
else
replyString="Your answer is wrong.\n"+num1+"-"+num2+"should be "+(num1-num2);
JOptionPane.showMessageDialog(null,replyString);
count++;
output = "\n"+num1+"-"+num2+"="+answerString+((num1-num2==answer)?"correct":"wrong");
}
long endTime =System.currentTimeMillis();
long testTime=System.currentTimeMillis();
JOptionPane.showMessageDialog(null,"Correct count is"+correctCount+
"\nTest time is"+testTime/1000+"seconds\n"+output);
}
}
用Eclipse编译运行后,出现如下错误。请多指教!
Exception in thread "main"
java.lang.Error: Unresolved compilation problem:
nun2
cannot be resolved to a variable
at TurtorLoop.main(TurtorLoop.java:25)
我是新手请大家多喷一喷,让我成长的更快些。多谢。
------解决方案--------------------
明显的拼写错误