Java Code that creates a random number between 1 and 100 and then asks the user to guess the number and tells if the guess was too high, too low or, the right number. Loops until right number is guessed.
Random number Game I made
// The "Random_Number_Guesser" class.
import java.awt.*;
import hsa.Console;
public class Random_Number_Guesser
{
static Console c;
public static void main (String[] args)
{
c = new Console ();
int on_off = 1;
long number = (Math.round(Math.random() * 100));
int guess;
while (on_off == 1)
{
c.println ("Guess a number between 1 and 101!");
guess = c.readInt ();
if (number > guess)
{
c.println ("Nope, too low.");
}
if (number < guess)
{
c.println ("Nope, too high.");
}
if (number == guess)
{
c.println ("Congrats, You got it!");
on_off = 0;
}
}
}
}
Dukane
sk8ndestroy14 294 Posting Virtuoso
kylethedarkn 23 A.K.A. The Laughing Man Team Colleague
StonedNpwnd 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.