Assignemnt #72 and Again with the Number-Guessing
Code
/// Name: Brian Phillips
/// Period: 5
/// Program name: NumberGuessing4.java
/// File Name: Again with the Number-Guessing
/// Date Finished: 1/15/2016
import java.util.Scanner;
import java.util.Random;
public class NumberGuessing4
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int choice = 1 + r.nextInt(10);
int tries = 0;
int entry;
System.out.println("Try to Guess my number between 1 and 10. ");
do
{
System.out.print("Your guess: ");
entry = keyboard.nextInt();
tries++;
if ( choice != entry)
System.out.println("That is incorrect. Guess again.");
} while ( entry != choice );
if ( entry == choice )
{
System.out.println( "Correct! That's my number. It only took you " + tries + " tries.");
System.out.println( " I post dank memes " + tries + " times a week. ");
}
}
}
Picture of the output