-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberQuiz.java
More file actions
27 lines (27 loc) · 990 Bytes
/
NumberQuiz.java
File metadata and controls
27 lines (27 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.example;
import java.util.Scanner;
public class NumberQuiz {
public static void main(String args[]){
//define two numbers and generate random number and assign integer type through type casting
int number1 = (int)(Math.random()*10);
int number2 = (int)(Math.random()*10);
//Subtraction is negative than resolve in below
if(number1 < number2){
int temp;
temp=number1;
number1=number2;
number2=temp;
}
//Display the statement and ask the questions
System.out.print("What is "+ number1 + " - " + number2 + "? :");
Scanner input = new Scanner(System.in);
int answer = input.nextInt();
//if Answer == number1 - number2 display correct else Incorrect and display number1-number2
if(number1 - number2 == answer)
System.out.println("Answer is Correct !");
else{
System.out.println("Answer is Incorrect !!");
System.out.println(number1 + " - " + number2 + " = " + (number1-number2));
}
}
}