Assignemnt #72 and NumGuessingAgain
Code
/// name: Leila Ordukhani
/// period: 6
/// program name: Sixty-Second Program
/// file name: NumGuessingAgain.java
/// date finished: 12/16/15
import java.util.Random;
import java.util.Scanner;
public class NumGuessingAgain
{
public static void main ( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int x = 1 + r.nextInt(10);
int guess;
int tries = 0;
System.out.println("I'm thinking of a number between 1 and 10. What is it?");
System.out.println("");
do {
System.out.print("guess: ");
guess = keyboard.nextInt();
tries++;
if (guess != x)
System.out.println("That's incorrect guess again.");
} while (guess != x);
System.out.println("That's right! It only took you " + tries + " tries");
}
}
Picture of the output