Write a program in JAVA to guess the number.
numGuess - Java Code
Number Guessing Game
ANSWER
numGuess - Java Code
import java.util.*;
public class numGuess
{
public static void main()
{
Scanner sc = new Scanner(System.in);
System.out.println("i'm thinking a number Can you Guess it");
int gus = (int)((Math.random() * 100) + 1);
int rnd = -1;
int attm = 1;
while (gus != rnd)
{
System.out.println("Enter the number: ");
rnd = sc.nextInt();
if (rnd > gus) {
System.out.println("Too High");
attm = attm + 1;
}
else if (rnd < gus) {
System.out.println("Too Low");
attm = attm + 1;
}
else {
System.out.println(gus + " is equal to " + rnd);
break;
}
}
System.out.println("Congratulation You guess the number only " + attm + " attems");
}
}
OUTPUT:
Number Guessing Game
I'm thinking of a number between 1 and 100. Can you guess it?