I am trying to make a guessing game where it generates a number from 1-9 and you have 4 guesses. Despite my best efforts im getting "Cannot resolve symbol" when i try to use randomNum after i initialized it in the start. // My first Java project so any help would be appreciated.
import java.util.Scanner;
public class GuessingGame {
public static void main(String[] args) {
int guess;
int guesses = 0;
Scanner input = new Scanner(System.in);
for (int i = 0; i <= 0; i = i + 1) {
int randomNum = (int)(Math.random() * 10);
System.out.println("I have created a number 0-9 can u guess it?");
System.out.println("You have 4 guesses");
}
while (guesses <= 4) {
guess = input.next().charAt(0);
if (guess == randomNum){
System.out.println("You guessed it! the number was" + " " + randomNum);
}
else {
System.out.println("Wrong!");
guesses = guesses + 1;
if(guesses > 4) System.out.println("U lost! the number was" + " " + randomNum);
}
}
input.close();
}
}