Assignemnt #72 and AnotherGuess.java
Code
/// Name: Boris Kazantsev
/// Period: 6
/// Program Name: AnotherGuess
/// File Name: AnotherGuess.java
/// Date Finished: 1/12/2016
import java.util.Scanner;
import java.util.Random;
public class AnotherGuess{
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int a, num = 1 + r.nextInt(10);
int tries = 0;
System.out.print("guess 0-10: ");
a = keyboard.nextInt();
tries++;
do{
System.out.println("Guess again: ");
a = keyboard.nextInt();
tries++;
}while ( a != num );
System.out.println("Yes! It only took you " + tries + " times.");
}
}
Picture of the output