In: Computer Science
The third task is to further refine the program so that
HINT: You need functions eight from the sample code (see previous activity).
Steps
Please use Netbeans to revise your NumberGuessGame program to satisfy the above requirements. Please submit a print screen of your successful code including the Output window with the "Build Successful" message to this assignment.
Code:
import java.util.Random;
import java.util.Scanner;
class guessnum
{
public static void main(String[] args)
{
Random random=new Random();/*Random
object*/
int
randnum=random.nextInt(100)+1;/*Random number between 1 to
100*/
int guess=0;/*Declaring
variable*/
Scanner scnr=new
Scanner(System.in);/*Scanner object*/
System.out.println("Guess the
Number:");
for(int
i=0;guess!=randnum;i++)
{
guess=scnr.nextInt();/*Reading users guess*/
if(guess>randnum)
{/*If guess is
greater than random*/
System.out.println("Too High\nTry
again!");
}
else
if(guess<randnum)
{/*If guess is
less than random*/
System.out.println("Too Low\nTry again!");
}
else
{/*If guessed
correctly*/
System.out.print("Congratulation you guessed the
number");
}
}
}
}
Output:
Indentation: