Assignemnt #72
Code
///Name: Joshua Bautista
///Period: 6
///Project Name: ShorterDoubleDice
///File Name: ShorterDoubleDice.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 ");
}
do
{
System.out.print(" Sorry, try again: " );
choice = keyboard.nextInt();
tries++;
}
while (choice != answer);
{
System.out.println(" Wow... your right my number is " + answer + "... you guessed " + tries + " times. ");
}
}
}
Picture of the output