forked from fenniless/BlueJ.TooLargeTooSmall
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessingGame.java
More file actions
45 lines (38 loc) · 1.17 KB
/
GuessingGame.java
File metadata and controls
45 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Write a description of class Main here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.Scanner;
public class GuessingGame
{
/**
* Constructor for objects of class Main
*/
public static void main (String [] args) {
Scanner game = new Scanner (System.in);
int x, guess,tries;
System.out.println("Welcome to the Guessing Game!");
System.out.println("Guess a number between 1 and 10");
guess = game.nextInt();
x = (int) (Math.random()*6 +1);
tries= 0;
while (guess != x) {
tries++;
if (guess < x){
System.out.println("Your guess is too small!");
System.out.println("Enter a number between 1 and 10");
guess = game.nextInt();
}
if (guess > x){
System.out.println("Your guess is too big!");
System.out.println("Enter a number between 1 and 10");
guess= game.nextInt();
}
if (guess == x){
System.out.println("Your guess is correct! You got it in " + tries + " tries");
}
}
}
}