Assignment #72

Code

 ///Name: Conner Wygaerts
///Period: 6
///Project Name: GuessingAgain
///File Name: GuessingAgain.java
///Date Finished: 1/8/16

    import java.util.Random;
  import java.util.Scanner;

public class GuessingAgain
{
	public static void main ( String[] args )
	{
		Random r = new Random();
        Scanner keyboard = new Scanner(System.in);
        
		int x = 1 + r.nextInt(10);
        int guess;
        int tries = 0;
        
        System.out.println("I'm thinking of a number between 1 and 10. What is it?");
        System.out.println("");
        
    do {
        System.out.print("guess: ");
		guess = keyboard.nextInt();
		tries++;
        
            if (guess != x)
            System.out.println("That's incorrect guess again.");
  
        } while (guess != x);
        
        System.out.println("That's right! It only took you " + tries + " tries");
        }
        }

Picture of the output

YourInitials.html