Assignment #65 and Number Guessing
Code
/// Name: Graham Pollock
/// Period: 5
/// Program Name: Number Guessing
/// File Name: NumberGuessing.java
/// Date Finished: 12/10/2015/
import java.util.Random;
import java.util.Scanner;
public class NumberGuesssing
{
public static void main(String[] args)
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int snumber, guess, count;
snumber = 1 + r.nextInt(10);
count = 0;
System.out.println("I'm thinking of a number between 1-10. Try to gues it!");
System.out.print("> ");
guess = keyboard.nextInt();
System.out.println("");
count++;
while (guess != snumber)
{
System.out.print("Wrong, try again: ");
guess = keyboard.nextInt();
System.out.println("");
count++;
}
System.out.println("That's right! You got it in " + count + " tries.");
}
}
Picture of the output