Assignemnt #72 and Again with the Number-Guessing
Code
///Name: Luke Shin
///Period: 7
///Project Name: AnotherGuessin
///File Name: AnotherGuessin.java
///Date: 12/18/2015
import java.util.Scanner;
import java.util.Random;
public class AnotherGuessin{
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