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