Win a copy of Kotlin in Action this week in the Kotlin forum!
    Bookmark Topic Watch Topic
  • New Topic

Urgent help with Homework  RSS feed

 
Junaid Mahmud
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 (System.in);

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

}

 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Duplicate topic... https://coderanch.com/t/670785/java/java/print-random-numbers

Please use original topic.

Henry
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!