Assignemnt #65 Number Guessing With A Counter
Code
///Name: Morgan Kaplan
///Period: 5
///Project Name: Number Guessing With A Counter
///File Name: GuessC.java
import java.util.Scanner;
public class GuessC
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int n = 3, guess, times=1;
System.out.println("I have chosen a number between 1-10.");
System.out.print("What do you think the number is? ");
guess = keyboard.nextInt();
while ( guess != n )
{
System.out.println("INCORRECT Number. TRY AGAIN.");
System.out.print("ENTER YOUR Number: ");
guess = keyboard.nextInt();
times ++;
}
System.out.println("That guess is right! It only took you " + times + " tries ");
}
}
Picture of Output