Assignemnt #67

Code

    ///Name: Joshua Bautista
    ///Period: 6
    ///Project Name: AddingValuesToLoop
    ///File Name: AddingLoop.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, tries;
        answer = 1 + r.nextInt(10);
        tries = 1;
        
        
        System.out.println(" I'm thinking of a number from 1 to 10." );
        System.out.print(" Your guess : ");
        choice = keyboard.nextInt();
        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.println(" Sorry, try again." );
            choice = keyboard.nextInt();
            tries++;
        if ( choice == answer )
        {
            System.out.println(" You are right, my number is " + answer + " this took you " + tries + " tries ");
        }
        }
    }
}
    

Picture of the output

Assignment 1