Assignment #72
Code
/// Gian Adoremos
/// Period: 7
/// Program Name: SeventySecond Program
/// File Name: Again.java
/// Date Finished: 12/7/2015
import java.util.Scanner;
import java.util.Random;
public class Again
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int guess;
int secretNumber = 1 + r.nextInt(10);
int tries = 0;
System.out.println("I have chosen a number between 1 and 10. Try to guess it.");
do
{
System.out.print("Your guess: ");
guess = keyboard.nextInt();
tries++;
if ( guess != secretNumber)
System.out.println("That is incorrect. Guess again.");
} while ( guess != secretNumber );
System.out.println("That's right! You're a good guesser.");
System.out.println("It only took you " + tries + " tries.");
}
}
Picture of the output