Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
    Bookmark Topic Watch Topic
  • New Topic

Urgent help with Homework  RSS feed

Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hey I am stuck on this homework assignment and really need help. I am suppose to print out two random numbers and the bigger number is suppose to subtract the smaller number. Not only that but I need a response for the user to solve the problem and if the answer is correct I then want it to display saying correct. If not I want it to display incorrect with what the problem was and the actual answer. The following is what I have so far. Thanks!!! PLEASE BE SPECIFIC!

package Labs;
// Allows the use of Scanner utility for user input
import java.util.Scanner;
import java.util.Random;
public class Lab4 {

public static void main(String[] args) {
// Declare variables
int number1 = (int) (Math.random() * 10);
int number2 = (int) (Math.random() * 10);
int answer;
Scanner keyboard = new Scanner (;

if(number1 >= number2)
System.out.println("What is: " + number1 + " - " +number2 );
answer = keyboard.nextInt();
if(answer == (number1 - number2));
if (answer != (number1 - number2));
if(number2 >= number1)
System.out.println("What is: " + number2 + " - " +number1 );
answer = keyboard.nextInt();


Posts: 23364
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Duplicate topic...

Please use original topic.

Anderson gave himself the promotion. So I gave myself this tiny ad:
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!