Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Urgent help with Homework

Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23951
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Duplicate topic...

Please use original topic.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic