It is a New Year and you may probably want to replace your smartphone you have been using for several…
CNC milling control machineHave you ever asked yourself how machines in a factory know exactly when to stop making the…
Program that randomly generates an addition question with two integers less than 100.
1 2 |
/**<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 here to see other solutions…
Technology is an important part of your lives. We can barely do without it. Consequently, you have developed some perennial…
If you’re familiar with MS-DOS at all, you’ll recall that it’s a command-driven operating system that performs functions issued at…