Assignment #72 and Again With The Number Guessing
Code
/// Name: Graham Pollock
/// Period: 5
/// Program Name: NGuessing
/// File Name: NGuessing.java
/// Date Finished: 1/14/2016/
import java.util.Scanner;
import java.util.Random;
public class NGuessing
{
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