Program that randomly generates an addition question with two integers less than 100.
|
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> */<br /><br />import java.util.Scanner;<br /><br />public class Ex03_10 {<br /> public static void main(String[] args) {<br /> // Generate two integers less than 100<br /> int number1 = (int) (Math.random() * 100);<br /> int number2 = (int) (Math.random() * 100);<br /><br /> // Prompt the user to answer "What is number1 + number2?"<br /> System.out.print("What is " + number1 + " + " + number2 + "? ");<br /> Scanner input = new Scanner(System.in);<br /> int answer = input.nextInt();<br /> // Grade the answer and display the result<br /> if (number1 + number2 == answer) {<br /> System.out.println("You are correct!");<br /> } else {<br /> System.out.println("Your answer is wrongn" + number1 + " + " + number2 + " is "<br /> + (number1 + number2));<br /> }<br /> }<br />}<br /> |
Sample program runClick…