Assignemnt #65 and A Guessing Game
Code
///Name: Daniel Tiffany-Appleton
///Period: 7
///Program Name: A Guessing Game
///File Name: AGuessingGame
///Date Finished: 12/2/15
import java.util.Scanner;
import java.util.Random;
public class AGuessingGame
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int guessNumber, secretNumber, triesNumber;
secretNumber = 1 + r.nextInt(10);
triesNumber = 1;
System.out.println( "I am thinking of a number between 1 and 10, including 1 and 10 " );
System.out.println( "" );
System.out.print( "What is your guess: " );
guessNumber = keyboard.nextInt();
while ( guessNumber != secretNumber )
{
triesNumber++;
System.out.println( "That's not it, guess again" );
System.out.println( "" );
System.out.print( "What is your guess: " );
guessNumber = keyboard.nextInt();
}
System.out.println( "Congratulations, you guessed right." );
System.out.println( "It only took you " + triesNumber + " tries." );
}
}
Picture of the output