Design and implement a JAVA application that plays the HiLo
Design and implement a JAVA application that plays the Hi-Lo guessing game with numbers. The program should pick a random number between 1 and 100 (inclusive), then repeatedly prompt the user that he or she is correct or that the guess is high or low. Continue accepting guesses until the user guesses correctly or choose to quit. Use a sentinel value to determine whether the user wants to quit. Count the number of guesses and report that value when the user guesses correctly. At the end of each game (by quitting or a correct guess), prompt to determine whether the user wants to play again. Continue playing games until the user chooses to stop.
Solution
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 package chegg;
import java.util.Scanner;
public class HiLo {
   
 public static void main(String[] args)
 {
 char playGame;
 char quit;
 Scanner input = new Scanner(System.in);
 int guesses = 0;
 int userInput;
 int answer;
 while(true)
 {
 answer = 1 + (int)(Math.random() * 100);
 guesses = 0;
 //System.out.println(\"Answer is \"+answer);
 while(true)
 {
 System.out.println(\"Input the value of your guess : \");
 guesses = guesses+1;
 userInput = input.nextInt();
 
 if(userInput>answer)
 System.out.println(\"Your Guess was high\");
 else if(userInput<answer)
 System.out.println(\"Your Guess was low\");
 else
 {
 System.out.println(\"Congratulation! it is a correct guess.You take \"+guesses+\" for guessing the answer.\");
 break;
 }
 
 System.out.println(\"Do you want to quit?(y/n)\");
 quit = input.next().charAt(0);
 if(quit==\'y\')
 break;
 
 }
 
 
 System.out.println(\"Do you want to play next game?(y/n)\");
 playGame = input.next().charAt(0);
 if(playGame!=\'y\')
 break;
 }
 
 
 }
   
 }


