Assignemnt #72

Code

///colin hinton
///5th period
///Guess
///Guess.java
///11/13/2015

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

class Guess
{
    public static void main (String [] args)
    {
        Scanner keyboard = new Scanner(System.in);
        Random rng = new Random();
        
        int ans, x , tries;
        x = 1 + rng.nextInt(10);
        tries = 0;
        System.out.println("I have chosen a number between 1 and 10, guess it.");
        do
        {
            System.out.print("Your guess : ");
            ans = keyboard.nextInt();
            tries++;
            if (x != ans)
            {
                System.out.println("Wrong, try again");
            }
        } while (x != ans);
        
        System.out.println("Congrats you guess " + x + " and it only took you " + tries + " tries.");
    }
}
    

Picture of the output

Assignment 1