public static void main (String args[]) { int number1 = (int)(Math.random() *10); int number2 = (int)(Math.random() *10); Scanner input = new Scanner(System.in); System.out.print("what is " + number1 + "+" + number2 + "?"); int answer = input.nextInt(); while(number1 + number2 != answer) { System.out.print("Wrong answer. Try again. What is " + number1 + "+" + number2 + "?"); answer= input.nextInt(); } System.out.println("You got it."); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter