Hi guys I have a little bug which needs an extra eye to see I cant seem to see it. Can you help. Thanks in advance

//CAI - Computer Assisted Instruction, multiplication program for first graders
//Instruction.java

import java.util.Random; //Program uses Random class
import java.util.Scanner;// Program uses Scanner class

public class Instruction
{
   //Main method to execute the java program
   public static void main (String[] args)
  {  
     //Scanner object to get input of the user
     Scanner input = new Scanner(System.in);

     generateRandom();//Calling generate number
     int answer = input.nextInt();

     if ( answer == generateRandom() )
     System.out.println("You are correct");

     else 
     System.out.println("You are incorrect");

  }//end method main

  public static int generateRandom()
  {
    Random randomNumbers = new Random();

    int digit1 = 1 + randomNumbers.nextInt(9);
    int digit2 = 1 + randomNumbers.nextInt(9);

    System.out.printf("How much is %d times %d", digit1, digit2);
    System.out.println();
    int result = digit1 * digit2;

    return result;
   }//end method generateRandom

}//end class Instruction
generateRandom();//Calling generate number
     int answer = input.nextInt();
     if ( answer == generateRandom() )

well, if you call it twice, it'll be executed twice.
replace the above by either:

 int answer = input.nextInt();
 if ( answer == generateRandom() )

or by

 int generated = generateRandom();//Calling generate number
 int answer = input.nextInt();
 if ( answer == generated )

Thanks Man It worked I was calling the method after getting the input. Thanks! `+stultuske

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.