Assignment 55, A Number-Guessing Game
Code
///Name: Stella Koliavas
///Period: 5
///Program Name: Guess 2
///File Name: Guess2.java
///Date Finshed: 12/3/15
import java.util.Scanner;
import java.util.Random;
public class Guess2
{
public static void main (String[] args)
{
Scanner siri = new Scanner(System.in);
Random r = new Random();
int x, s;
s = 1 + r.nextInt(10);
System.out.println("Let's play a guessing game, I'm thinking of a number between 1-10.");
System.out.print("Your guess: ");
x = siri.nextInt();
if (s == x)
System.out.println("You guessed the number right!");
if (s != x )
System.out.println("You guessed wrong! I was really thinking of " + s + ".");
}
}
Picture of the output