Assignemnt #65 - Guessing
Code
/// Name: Caelan Dorstad
/// Period: 6
/// Program Name: guessin
/// File Name: guessin.java
/// Date Finished: 1/5/2016
import java.util.Scanner;
import java.util.Random;
public class guessin{
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