Zaid A Zaid A - 10 months ago 55
Java Question

Cannot find symbol for .hasNextInt

import java.util.*;

public class NGGs {

static int RandomNum1 = (int) (Math.random() * 11);

static int guessTyped;

static Scanner guessedNumber;

static String answer;

static Scanner reply;

public static void main(String[] args) {

guess(guessTyped, guessedNumber, RandomNum1);

public static void guess(int userGuess, Scanner userInput, int RandomNum1) {


System.out.println("Im thinking of a Number between 1 to 10.....");

System.out.print("Try to guess it: ");

userInput = new Scanner(;

userGuess = userInput.nextInt();

if (!userInput.hasNextInt) {

System.out.println("That wasn't the answer I was quite looking for, try typing in a number that doesn't have decimals!");


} else {

guessChecker(guessTyped, guessedNumber, RandomNum1);

} while (userGuess != RandomNum1);


public static void guessChecker(int userGuess, Scanner userInput, int RandomNum1) {

if (userGuess == RandomNum1) {


} else {

retryChecker(reply, answer);


public static void retryChecker(Scanner userReply, String userChoice) {

System.out.println("Would you like to try again ?");

userReply = new Scanner(;

userChoice = userReply.nextLine();

if (userChoice.equalsIgnoreCase("yes") || userChoice.equalsIgnoreCase("y")) {

guess(guessTyped, guessedNumber, RandomNum1);

} else {



public static void delay(int millis) {

try {


} catch (InterruptedException exp) {}


ok so there's my code. (btw NGGs stands for NumberGuessingGame).
so im trying to say that if userInput is not an Integer then print out:
That wasn't the answer I was quite looking for, try typing in a number that doesn't have decimals!
but, it says cannot find symbol and i cannot solve the issue and it's bothering me alot.
Thanks for the help.

Answer Source

The problem is that in Java, we are invoking methods with using "(...)" with list of method parameters in "..." place. (in case of lambdas and method references there is the other way).
userInput.hasNextInt() is not o field, it's a method so this rule have to be applied.
So in your code, you should repleace:

if (!userInput.hasNextInt) {


if (!userInput.hasNextInt()) {

Hope it helps.