import java.util.Random; import java.util.Scanner; public class AdditionQuiz3 { public static void main(String args[]) { Random random = new Random(); Scanner in = new Scanner(System.in); String ans; do { int n1 = random.nextInt(10); int n2 = random.nextInt(10); System.out.print(n1 + " + " + n2 + " = "); int sum = in.nextInt(); boolean correct = (n1 + n2 == sum); String msg = n1 + " + " + n2 + " = " + sum; if (correct) msg += " is correct"; else msg += " is incorrect"; System.out.println(msg); System.out.print("Do you want to try another one? [Y|N]: "); ans = in.next(); } while (ans.equalsIgnoreCase("Y")); System.out.println("Quiz closed."); in.close(); } }