Assignemnt #73
Code
/// Name: Connor Siri
/// Period: 7
/// Program Name: Guess
/// File Name: Guess.java
/// Date Finished: 11/10/2015
import java.util.Random;
import java.util.Scanner;
public class Guess
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int x = 1 + r.nextInt(10), y, n;
n=0;
System.out.println("I have choosen a number between 1 and 10. Guess it");
do
{
System.out.print("Your Guess: ");
y = keyboard.nextInt();
System.out.println("That is incorrect. Try again");
n++;
System.out.println("");
} while ( x != y );
System.out.println("You got it right good job. it took you " + n + " tries");
}
}
Picture of the output