Assignemnt #65

Code

    ///Name: Joshua Bautista
    ///Period: 6
    ///Project Name: NumberGuessingWithCounter
    ///File Name: NumberCounter.java
    ///Date: 1/7/2016
    
    import java.util.Scanner;
import java.util.Random;

public class NumG
{
    public static void main( String[] args )
    {
        
        Scanner keyboard = new Scanner(System.in);
        Random r = new Random();
        int choice, answer;
        answer = 1 + r.nextInt(10);
        int tries = 0;
        
        System.out.println(" I'm thinking of a number from 1 to 10." );
        System.out.print(" Your guess : ");
        choice = keyboard.nextInt();
        tries++;
        System.out.println();
        if (choice == answer)
        {
            System.out.print(" Wow... your right my number is " + answer + "... you should go to Harvard ");
        }
        while (choice != answer)
        {
            System.out.print(" Sorry, try again -" );
            choice = keyboard.nextInt();
            tries++;
        if ( choice == answer )
        {
            System.out.println(" Wow... your right my number is " + answer + "... you guessed " + tries + " times. ");
        }
        }
    }
}
    

Picture of the output

Assignment 1