Assignemnt #72 and A New Guessing Game
Code
///Name: Daniel Tiffany-Appleton
///Period: 7
///Program Name: A New Guessing Game
///File Name: ANewGuessingGame
///Date Finished: 12/9/15
import java.util.Scanner;
import java.util.Random;
public class ANewGuessingGame
{
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 = 0;
System.out.println( "I am thinking of a number between 1 and 10, including 1 and 10 " );
System.out.println( "" );
do
{
System.out.println( "That's not it, guess again" );
System.out.print( "What is your guess: " );
guessNumber = keyboard.nextInt();
System.out.println( "" );
triesNumber++;
}while ( guessNumber != secretNumber );
System.out.println( "Congratulations, you guessed right." );
System.out.println( "It only took you " + triesNumber + " tries." );
}
}
Picture of the output