我不知道如何使“数字2”不等于零,因为如果它等于零,那将是一个例外。
我试图让2自动生成,因为如果自动生成,则2的可能性很小,但是它仍然会发生。
number1=(int) (Math.random()*10); //Number 1 auto generate
number2=(int) (Math.random()*10); //Number 2 auto generate
System.out.println(number1+"/"+number2);
answer=sc.nextInt();
if(answer==(number1/number2))
{
System.out.println("You are correct, you get one point!");
points=points+1;
System.out.println("You have "+points+"points");
}
else
{
System.out.println("You are not correct, you get no point! I am sorry.");
points=points+0;
System.out.println("You have "+points+"points");
}
我希望它不为0,但确实如此,并且会弹出异常。