Assignemnt #55

Code

    ///Name: Joshua Bautista
    ///Period: 6
    ///Project Name: A Number Guessing Game
    ///File Name: NumG.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);
        
        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 ");
        }
        else if (choice != answer)
        {
            System.out.println(" Sorry my number is " + answer + "." );
        }
    }
}
    

Picture of the output

Assignment 1