Assignemnt #72
Code
/// Name: Daniel Nguyen
/// Period: 6
/// Program Name: agnumber Program
/// File Name: agnumber.java
/// Date Finished: 9/9/2015
import java.util.Random;
import java.util.Scanner;
public class agnumber
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random rng = new Random();
int guess = 0;
int tries = 0;
int number;
number = 1 + rng.nextInt(10);
System.out.println("I have chosen a number between 1-10 try to guess it noob");
do {
System.out.print("Your Guess: ");
guess = keyboard.nextInt();
tries++;
if ( guess != number ) {
System.out.println("Wrong! Try again!");
}
} while ( number != guess );
if (tries != 0) {
System.out.println("That took " + tries + " tries.. but at least you got it");
}
else {
System.out.println("Nice! That was really good! it took zero tries!");
}
}
}
Picture of the output