Assignemnt #72 Again With The Number Guessing
Code
///Name: Morgan Kaplan
///Period: 5
///Project Name: Again With The Number Guessing
///File Name: AWTNG.java
import java.util.Scanner;
import java.util.Random;
public class AWTNG
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r= new Random();
int guess, n, tries=1;
System.out.println("I have chosen a number between 1-10.");
n= 1 + r.nextInt(10);
System.out.print("Enter Number? ");
guess = keyboard.nextInt();
do
{
System.out.println("INCORRECT Number. TRY AGAIN.");
guess = keyboard.nextInt();
tries ++;
}
while ( guess != n );
System.out.println("That guess is right! It only took you " + tries + " tries ");
}
}
Picture of Output