Assignemnt #65 and GuessingWithCount
Code
/// name: Leila Ordukhani
/// period: 6
/// program name: Fifty-Fifth Program
/// file name: GuessingWithCount.java
/// date finished: 12/4/15
import java.util.Random;
import java.util.Scanner;
public class GuessingWithCount
{
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("");
System.out.print("guess: ");
guess = keyboard.nextInt();
tries++;
while (guess != x)
{
System.out.println("That's incorrect guess again.");
System.out.println("");
System.out.print("guess: ");
guess = keyboard.nextInt();
tries++;
}
System.out.println("That's right! It only took you " + tries + " tries");
}
}
Picture of the output