0

I found a similar question but didn't find a relevant answer. I am trying to create a table memorizer and I am able to get the input number from user using scanner.nextInt() . But it is not same for string for which I am using scanner.nextLine().

boolean _continue = true;
       while (_continue){
           Random random = new Random();
           int num1 = random.nextInt(limitNum1);
           int num2 = random.nextInt(limitNum2);

           System.out.print(num1 +"*"+ num2 +" = ");
           int answer = scanner.nextInt();
           int correctAnswer = num1*num2;
           if(answer==correctAnswer){
               System.out.print("Correct\nContinue ");
           }else{
               System.out.print("Incorrect. Correct answer for "+ num1 + "*" + num2 + " is " + correctAnswer + "\nContinue ");
           }
           String temp = scanner.nextLine();
           if(!(temp.equals("y")) || !(temp.equals("Y"))){
               _continue=false;
           }
       }

Kindly help

Hector
  • 1

0 Answers0