Assignment #58
Code
/// Name: Sam Wilson
/// Period: 6
/// Program Name: countingcounter
/// File Name: countingcounter.java
/// Date Finished: 12/9/2015
import java.util.Scanner;
import java.util.Random;
public class countingcounter
{
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);
while (choice != i)
{
System.out.println("You guessed incorrectly! Try Again.");
System.out.println();
System.out.print("> ");
i = key.nextInt();
n++;
}
System.out.println("Congrats you guessed correctly!");
System.out.println("It only took "+n+" times");
}
}
Picture of the output