Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication1;
- import java.util.Scanner;
- public class JavaApplication1
- {
- public static void main(String[] args)
- {
- int num1, num2;
- num1 = (int)(Math.random() * 10); //Generates an int 0 <= x < 10
- num2 = (int)(Math.random() * 10); //Generates an int 0 <= x < 10
- Scanner input = new Scanner(System.in);
- //Make the larger number num1
- if (num2 > num1)
- {
- int temp = num2; //Ty dreamreal and Manis for this code snippet.
- num2 = num1;
- num1 = temp;
- }
- System.out.print("What is " + num1 + " - " + num2 + " = ");
- int guess = input.nextInt(); //Get input from user.
- if (guess == num1 - num2)
- System.out.println("Yes, it is. ");
- else
- System.out.println("WRONG! It's " + (num1 - num2));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement