Я пишу простую математическую игру (bluej, java), в которой пользователю задают 5 случайных математических вопросов с использованием оператора if внутри оператора для l oop. Они генерируются с помощью Math.random, и пользователю дается процент от того, сколько вопросов он получил в конце.
По какой-то причине в последних двух строках есть ошибки, такие как «недопустимый запуск типа» и «не оператор». и я не могу понять, что (или где) ошибка.
public class withIF
{
public static void main (String args [] )
{
new withIF ();
}
public withIF ()
{
int points = 0;
int num1 = 0;
int num2 = 0;
for (int i = 1; i<6; i++)
{
num1 = ((int) (Math.random () * 5)) + 1;
num2 = ((int) (Math.random () * 5)) + 1;
int ans = IBIO.inputInt ("Answer this question: " + num1 + " + " + num2 + " = ");
if (ans == (num1 + num2))
{
System.out.println ((num1 + num2) + " is correct! You got it right!");
points++;
}
else
{
System.out.println ((num1 + num2) + " is the correct answer, not " + ans);
System.out.println ("Score: " + points);
}
}
System.out.println (" ");
int final = points * 20; //here is the error!
System.out.println ("You got " +final+ "% of questions correct"); //here is the error!
}
}