Assignment 61, Keep Guessing
Code
///Name: Stella Koliavas
///Period: 5
///Program Name: Guess4
///File Name: Guess4.java
///Date Finshed: 12/9/15
import java.util.Scanner;
import java.util.Random;
public class Guess4
{
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();
while (s != x )
{
System.out.println(" ");
System.out.println("You guessed wrong!");
System.out.print("Try again: ");
x = siri.nextInt();
}
if (s == x)
System.out.println("You guessed the number right!");
}
}
Picture of the output