0

My question is that the program is suppose to randomly generate a addition question with two integers less than 100

this is what i have so far:

import java.util.Scanner;

public class ex3_13 {
  public static void main(String[] args) {
    // 1. Generate two random single-digit integers
    int number1 = (int)(Math.random() * 100);
    int number2 = (int)(Math.random() * 100);

    // 2. If number1 < number2, swap number1 with number2
    int temp = 0;
    if (number1 < number2)
       temp = number1;
      number1 = number2;
      number2 = temp;
    

    // 3. Prompt the student to answer “what is number1 – number2?”
    System.out.println("What is " + number1 + " + " + number2 + "? ");
    Scanner input = new Scanner(System.in);
    int answer = input.nextInt();

    // 4. Grade the answer and display the result
    if (number1 + number2 == answer)
      System.out.println("You are correct!");
    else
      System.out.println("Your answer is wrong.\n" + number1 + " + "
        + number2 + " should be " + (number1 + number2));
  }
}

I am using netbeans and it says there is no errors but when I run the program it does not show the prompt in output

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by javaAddict
0

If you want more than 1 command to be executed "under" the if, you will need brackets:

if (number1 < number2)
..
..
..
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.