Assignemnt #72 and Again with Guessing Game
Code
/// Name: David Shkolnikov
/// Period: 6
/// Program Name: Again With Number Guessing
/// File Name: AgainWithNumberGuessing.java
/// Date Finished: 1/6/2016
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 guess, number = 1 + r.nextInt(10), count = 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();
count++;
if ( guess == number )
System.out.println("That's right! You're a good guesser.");
else
System.out.println("That is incorrect. Guess again.");
}
while ( guess != number );
System.out.println("It only took you " + count + " tries.");
}
}
Picture of the output