Assignemnt #65 and Guess.java
Code
/// Name: Boris Kazantsev
/// Period: 6
/// Program Name: Guess
/// File Name: Guess.java
/// Date Finished: 1/14/2016
import java.util.Scanner;
import java.util.Random;
public class Guess{
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++;
while ( a != num ){
System.out.println("Guess again: ");
a = keyboard.nextInt();
tries++;
}
System.out.println("Yes! It only took you " + tries + " times.");
}
}
Picture of the output