Sunday, 16 December 2012
A Little Java Game That Asks A User To Guess A Random Number From The Width Specified By The User.
import java.util.Scanner;
public class GuessNumber
{
public static void main( String[] args )
{
Scanner input = new Scanner( System.in );
System.out.print( "Please Enter A Number To Be Shuffled: " );
int x = input.nextInt();//Asks for width Of Random Number to Be Generated
int y = (int) (Math.random() * x);//Generates Random Number
System.out.print( "Now Guess The Random Number Generated: " );
int z = input.nextInt();//Asks For The User's Number
/*Requests for User number and checks if it
is the newly generated random number*/
while (z != y) {
System.out.println( "\nThis is the right Number " + y );
System.out.print( "Please Try again Till You Get the Right Number: " );
z = input.nextInt();
y = ( int ) ( Math.random() * x );
}
System.out.println( "CORRECT" );//Breaks Loop and Prints if Number Matches
}
}
Subscribe to:
Post Comments (Atom)
pfft!!!
ReplyDeleteGo else where and connect your wires...
ReplyDelete@Seton!!! go play else where, i'm busy...B-)
ReplyDelete