I have made a basic math game that asks you questions and tells you if you have answered them correctly or incorrectly. The game runs great! The thing is that it asks you a question one time and after you answer you have to run the program again. I want to get the program to ask ten questions. After that I want to figure out a scoring system for it but the first step is to get it to ask my ten questions. Here is my code.
package pkgnew;
import java.util.Scanner;
import java.util.Random;
public class New {
public static void main(String args[]) {
//Declare and construct variables
Random randomnum = new Random();
int fnum, snum, answer;
int mathnumber = randomnum.nextInt(20);
int newnumber = randomnum.nextInt(20);
//Declare and construct variables of math problem
fnum = mathnumber;
snum = newnumber;
answer = fnum + snum;
//Output of math problem
System.out.print(fnum);
System.out.print("+");
System.out.println(snum);
Scanner serena = new Scanner(System.in);
int userAnswer = serena.nextInt();
//If user input = answer display "correct"
if (userAnswer == answer) {
System.out.println("Correct!");
//If user input does not = answer display "wrong" and correct answer
} else {
System.out.print("Wrong!");
}
}
}