Assignemnt #55
Code
///colin hinton
///5th period
///Guessing Game
///GuessingGame.java
///10/29/2015
import java.util.Scanner;
import java.util.Random;
class GuessingGame
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner(System.in);
int guess;
System.out.println("Hello friends, try and guess a number 1-10");
guess = keyboard.nextInt();
Random r = new Random();
int x = (1 + r.nextInt(10));
if (x == guess)
{
System.out.println("Congrats you guessed correctly!");
}
if (x != guess)
{
System.out.println("Sorry the correct number was " + x);
}
}
}
Picture of the output