Assignemnt #61
Code
///Name: Joshua Bautista
///Period: 6
///Project Name: KeepGuessing
///File Name: keepGuesing.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 ");
}
while (choice != answer)
{
System.out.println(" Sorry, try again." );
choice = keyboard.nextInt();
if ( choice == answer )
{
System.out.println(" Wow... your right my number is " + answer + "... you should go to Harvard ");
}
}
}
}
Picture of the output