Assignemnt #66
Code
///Name: Joshua Bautista
///Period: 6
///Project Name: Hi-Lo with limited tries
///File Name: Hi-Lo.java
///Date: 1/7/2016
import java.util.Random;
import java.util.Scanner;
public class HiLo
{
public static void main( String[] args )
{
Scanner keyboard= new Scanner(System.in);
Random r = new Random();
int guess, ansewer;
int Rnum = 1 + r.nextInt(100);
int MaxTries = 8;
int tries = 1;
System.out.print(" I'm thinking of a number between 1-100. You have 7 guesses. ");
System.out.print(" First Guess: " );
guess = keyboard.nextInt();
while ( guess != Rnum && tries < MaxTries )
{
if ( guess > Rnum )
{
System.out.println(" Sorry, you guessed to high ");
}
else if ( guess < Rnum )
{
System.out.println(" Sorry, you guessed to low ");
}
System.out.print(" Guess # " + (tries + 1) + ": ");
guess = keyboard.nextInt();
tries++;
}
if ( guess == Rnum )
{
System.out.println(" Wow you guessed it! ");
}
else if ( tries == MaxTries )
{
System.out.print(" You have used up all your tries ");
}
}
}
Picture of the output