KeepGuessingTries
Code
import java.util.Random;
import java.util.Scanner;
public class KeepGuessingTries
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int num, tries;
tries = 0;
System.out.println( "pick number from 1-10" );
num = keyboard.nextInt();
tries++;
Random r = new Random();
int choice = 1 + r.nextInt(10);
String response = "";
while ( num != choice )
{
System.out.println( " TRY AGAIN guess" + tries );
num = keyboard.nextInt();
tries++;
}
if ( num == choice )
{
System.out.println( "NICE" );
}
}
}
KeepGuessingTries