Assignemnt #66
Code
/// Name: Connor Siri
/// Period: 7
/// Program Name: Counter
/// File Name: Counter.java
/// Date Finished: 11/03/2015
import java.util.Random;
import java.util.Scanner;
public class Counter
{
public static void main( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int x = 1 + r.nextInt(10);
int tries = 0;
System.out.println("Pick a number between 1 and 10");
System.out.print("> ");
int entry = keyboard.nextInt();
tries++;
while ( entry != x )
{
System.out.println("\n Incorrect number. try again");
System.out.print("> ");
entry = keyboard.nextInt();
tries++;
}
if ( entry == x )
System.out.println("\nYou got it right");
System.out.println("Number of tries = " + tries);
}
}
Picture of the output