Assignment 65, Number Guesser with Counter
Code
///Name: Stella Koliavas
///Period: 5
///Program Name: Pin
///File Name: Pin.java
///Date Finshed: 12/16/15
import java.util.Scanner;
import java.util.Random;
public class Guess5
{
public static void main (String[] args)
{
Scanner siri = new Scanner(System.in);
Random r = new Random();
int x, s;
int tries = 0;
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();
tries++;
}
if (s == x)
System.out.println("You guessed the number right and it only took you " + (tries +1) + " guesses!");
}
}
Picture of the output