forked from fenniless/BlueJ.TooLargeTooSmall
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
51 lines (35 loc) · 1.25 KB
/
Main.java
File metadata and controls
51 lines (35 loc) · 1.25 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
45
46
47
48
49
/**
* Write a description of class Main here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.Random;
import java.util.Scanner;
public class Main
{
public static void Main(String args[])
{
Random randomNumber = new Random();
int rando = randomNumber.nextInt(10) + 1;
Scanner scanner = new Scanner(System.in);
int guesses = 0;
int input = -1;
System.out.println("Welcome to the guessing game! Guess between 1-10 to win.");
while(true) {
int previousGuess = input;
input = scanner.nextInt();
if(input == rando) {
System.out.println("You are correct." + "You took " + guesses + " guesses");
break;
}
else if(input >rando) {
guesses = (input == previousGuess) ? guesses : (guesses + 1);
System.out.println("You are too high!" + "You took " + guesses + " guesses");
} else if (input < rando) {
guesses = (input == previousGuess) ? guesses : (guesses + 1);
System.out.println("You are too low!" + "You took " + guesses + " guesses");
}
}
}
}