Assignemnt #66 and Hi Lo with Limit
Code
/// Name: Brian Phillips
/// Period: 5
/// Program name: Hi Lo with Limit
/// File Name: SevenShotHiLo.java
/// Date Finished: 1/4/2016
import java.util.Scanner;
import java.util.Random;
public class SevenShotHiLo
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int choice = 1 + r.nextInt(100);
int hisNumber;
int tries = 0;
int max = 7;
System.out.println("Number Guessing Game");
System.out.println();
System.out.println("Try to Guess my number between 1 and 100. ");
hisNumber = keyboard.nextInt();
tries++;
System.out.println();
if ( choice == hisNumber )
{
System.out.println( "Wow" + choice + " was my number." );
}
while ( choice != hisNumber && tries <= max )
{
System.out.println( "Sorry that is not my number. Guess again.");
hisNumber = keyboard.nextInt();
tries++;
}
if( tries == 8 );
{
System.out.println( "Sorry you didn't guess in 7 tries. You lose");
}
}
}
Picture of the output