Assignment #64
Code
/// Name: Sam Wilson
/// Period: 6
/// Program Name: guessingcounter
/// File Name: guessingcounter.java
/// Date Finished: 1/5/2015
import java.util.Scanner;
import java.util.Random;
public class guessingcounter
{
public static void main(String[] args)
{
Random s = new Random();
Scanner key = new Scanner(System.in);
int i;
int choice = 1 + s.nextInt(10);
int n = 1;
System.out.print("I'm thinking of a number between 1 and 10 try to guess it: ");
i = key.nextInt();
System.out.println();
System.out.println("Your guess: " +i);
do
{
System.out.println("You guessed incorrectly! Try Again.");
System.out.println();
System.out.print("> ");
i = key.nextInt();
n++;
} while (choice != i);
System.out.println("Congrats you guessed correctly!");
System.out.println("It only took "+n+" times");
}
}
Picture of the output