import java.util.Random; import java.util.Scanner; public class AdditionQuiz2 { public static void main(String args[]) { Random random = new Random(); int n1 = random.nextInt(10); int n2 = random.nextInt(10); Scanner in = new Scanner(System.in); 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); /* Another way to do this */ // String msg = n1 + " + " + n2 + " = " + sum + " is incorrect"; // if (correct) // msg = n1 + " + " + n2 + " = " + sum + " is correct"; // System.out.println(msg); in.close(); } }