Assignemnt #65
Code
/// Name: Ryan Volko
/// Period: 7
/// Program Name: Counter
/// File Name: Counter.java
/// Date Finished: 12/10/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 y = 1 + r.nextInt(10);
int tries = 0;
System.out.println("Pick a number between 1 and 10");
System.out.print("Your guess: ");
int entry = keyboard.nextInt();
tries++;
while ( entry != y )
{
System.out.println("\nThat is wrong. Try again");
System.out.print("Your guess: ");
entry = keyboard.nextInt();
tries++;
}
if ( entry == y )
System.out.println("\nThat is Correct");
System.out.println(" Number of tries= " + tries);
}
}
Picture of the output