I am trying to build a guessing game for an assignment I am currently working on using loops. I am trying to get my game to give the user the option to play again. I was having a hard time trying to set up this last bit of code so I followed an example on youtube. Although I have declared the variable restart the compiler keeps telling me I have not initialized it. Any help with this code would be appreciated
import java.util.Scanner;
import java.util.Random;
public class High_Low_Game {
public static void main (String[] args){
Random rand=new Random();
Scanner scan= new Scanner(System.in);
int guess,num,count=0;
String restart;
num=rand.nextInt(99+1);
do{
System.out.println("Please enter a number from 1-100,press 0 to quit");
guess=scan.nextInt();
count++;
while(guess!=0)
if(guess>num){
System.out.println("Your guess was too high, try again");
guess=scan.nextInt();
count++;}
else
if(guess<num){
System.out.println("The number is too low,enter another guess ");
guess=scan.nextInt();
count++;}
else
if(guess==num){
System.out.println("You have guessed correctly");
System.out.println("It took you "+count+ " guesses");
System.out.println("Would you like to play again? (Y/N)");
restart=scan.next();}
}while(restart.equals("Y"));
}
}