import java.util.Scanner;
public class JavaApplication44 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter you name: ");
String name = scan.nextLine();
System.out.print("Enter your operation (+,-,*,/): ");
String operator = scan.nextLine();
System.out.print("Enter the range of the problems: ");
int ran = scan.nextInt();
System.out.print("Enter number of problems: ");
int problems = scan.nextInt();
int score = 0;
for (int i = 1; i <= ran; i++){
int first = (int)(Math.random()*ran);
int sec = (int)(Math.random()*ran);
System.out.print("Problem #"+i+": "+first + " "+operator+" "+sec+" = ");
int ans = scan.nextInt();
if (operator.equals("+")){
if (ans == first + sec){
System.out.println("Correct!");
score++;
}
else{
System.out.println("Wrong. The correct answer is "+(first+sec));
}
}
else if(operator.equals("-")){
if (ans == first - sec){
System.out.println("Correct");
score++;
}
else{
System.out.println("Wrong. The correct answer is "+(first - sec));
}
}
else if (operator.equals("*")){
if (ans == first * sec){
System.out.println("Correct");
score++;
}
else{
System.out.println("Wrong. The correct answer is "+(first * sec));
}
}
else if (operator.equals("/")){
if (ans == first / sec){
System.out.println("Correct");
score++;
}
else{
System.out.println("Wrong. The correct answer is "+(first / sec));
}
}
}
System.out.println(name+", you answered "+score+" questions correctly.");
}
}
I hope this helps!