Assignment #65
Code
///Name: Cody Swain
///Period: 6
///Project Name: ThreeCardMonte
///File Name: ThreeCardMonte.java
///Date: 12/2/15
import java.util.Random;
import java.util.Scanner;
public class NumberGameWithCounter
{
public static void main( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int secretNumber = 1 + r.nextInt(10);
int guess, numberofTries = 1;
System.out.println("I'm thinking of a number between 1-10 ");
System.out.println();
System.out.print("Yout Guess: ");
guess = keyboard.nextInt();
while ( guess != secretNumber ){
System.out.println("Nope, guess again: ");
guess = keyboard.nextInt();
numberofTries++;
}
System.out.println("That's correct, my secret number was " + secretNumber );
System.out.println("You guessed " + numberofTries + " times. " );
}
}
Picture of the output