Assignment #72
Code
/// Name: Ian Stanko
/// Period: 5
/// Program Name: NumberGuessing
/// File Name: NumberGuessing.java
/// Date Finished: 1/13/2016
import java.util.Scanner;
import java.util.Random;
public class NumberGuessing
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int snumber, guess, n;
snumber = 1 + r.nextInt(10);
n = 0;
System.out.println("I'm thinking of a number between 1-10. Try to guess it!");
do
{
System.out.print("Your guess: ");
guess = keyboard.nextInt();
System.out.println("Wrong, try again.");
n++;
} while (guess != snumber);
System.out.println("That's right! it took you " + n + "tries");
}
}
Picture of the output