Assignment 72, Again with the Number-Guessing
Code
///Name: Stella Koliavas
///Period: 5
///File Name: Guess6.java
///Date Finshed: 1/13/16
import java.util.Scanner;
import java.util.Random;
public class Guess6
{
public static void main (String[] args)
{
Scanner siri = new Scanner(System.in);
Random r = new Random();
int x, s;
int tries = 1;
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 and it only took you " + (tries) + " guesses!");
}
else
{
do
{
System.out.println("You guessed wrong!");
System.out.print("Try again: ");
x = siri.nextInt();
tries++;
}while (s!= x);
if (s == x)
{
System.out.println("You guessed the number right and it only took you " + (tries) + " guesses!");
}
}
}
}
Picture of the output