Code example for Scanner

Methods: hasNextInt, nextInt

0
 
		getRandomNumber(); 
		int guess = 1;
 
		System.out.println("Guess a number (" + randomNumber + "): ");
		if (userInput.hasNextInt()) {
			System.out.println("Checking for valid number...");
			guess = userInput.nextInt();
			if (guess <= 50 && guess >= 0) {
				System.out.println("Checking your guess...");
				checkGuess(guess);
				if (result == 1) {
					System.out.println("You're correct!");
				} else { 
					System.out.println("You're wrong!");
				} 
			} else { 
				System.out.println("Number must be between 0 and 50!");
			} 
		} else { 
			System.out.println("Not a number!");