Assignment #65 and Number-Guessing with a counter
Code
/// Name: Lauren Baird
/// Period: 7
/// Program Name: Number-Guessing with a counter
/// File Name: NGCounter.java
/// Date Finished: 11/4/2015
import java.util.Scanner;
import java.util.Random;
public class NGCounter
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int guess;
int number = 1 + r.nextInt(10);
System.out.println();
System.out.println( "I'm thinking of a number from 1-10. Try and guess." );
System.out.print( "Your guess: " );
guess = keyboard.nextInt();
int n = 0;
while ( guess != number )
{
System.out.println();
System.out.println( "That was incorrect. Guess Again." );
System.out.print( "Your guess: " );
guess = keyboard.nextInt();
n++;
}
System.out.println();
System.out.println( "You got it!" );
System.out.println( "It only took you " + (n+1) + " tries." );
}
}