Assignemnt #66
Code
/// Name: Holden Ganch
/// Period: 7
/// Program Name: sixty sixth Program
/// File Name: HiLo.java
/// Date Finished: 12/10/2015
import java.util.Random;
import java.util.Scanner;
public class HiLo
{
public static void main( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int x = 1 + r.nextInt(100);
int tries = 0;
System.out.println("Pick a number between 1 and 100");
System.out.println("You better guess well thought becuase you only have seven guesses");
System.out.print("Guess #" + (tries+1) + ": ");
int entry = keyboard.nextInt();
tries++;
while ( entry != x && tries < 7 )
{
if (entry > x)
{
System.out.println("\n Sorry to high");
System.out.print("guess #" + (tries+1) + ": ");
entry = keyboard.nextInt();
tries++;
}
else if ( entry < x )
{
System.out.println("\n you need to guess higher, try agian!");
System.out.print("guess #" + (tries + 1) + ": ");
entry = keyboard.nextInt();
tries++;
}
}
if ( entry == x )
{
System.out.println("\nYou got it right");
System.out.println("Wow thats impressive! congrats!");
}
else if ( tries >= 7 )
{
System.out.println("You are out of tries, you can try again if you wish to test your luck again.");
}
}
}
Picture of the output