-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathMain.java
More file actions
45 lines (40 loc) · 1.66 KB
/
Main.java
File metadata and controls
45 lines (40 loc) · 1.66 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
/**
* Created by iyasuwatts on 10/17/17.
*/
import java.util.Scanner;
public class Main {
public static void main(String[] args){
int max = 25;
int min = 0;
int randomNumber = (int) ((max+1) * Math.random()); //25
boolean correctGuess = false;
int guessCount = 0;
int lastGuess = min - 1;
System.out.println("random number is " + randomNumber);
Scanner enterGuess = new Scanner(System.in);
while(correctGuess == false){
System.out.println("Guess a number between 1 and 25. Please guess WHOLE NUMBERS ONLY");
String guess = enterGuess.nextLine();
int guessInt = Integer.parseInt(guess);
if(lastGuess == guessInt && guessCount > 0) {
System.out.println("You guessed the same number twice in a row");
}else if(guessInt > max || guessInt < min) {
System.out.println("You guessed a number outside of the range.");
lastGuess = guessInt;
guessCount++;
}else if(guessInt < randomNumber && guessInt > min - 1 ){
System.out.println("Guess higher next time.");
lastGuess = guessInt;
guessCount++;
}else if(guessInt > randomNumber && guessInt < max + 1 ){
System.out.println("Guess lower next time.");
lastGuess = guessInt;
guessCount++;
}else if(guessInt == randomNumber){
guessCount++;
System.out.println("You guessed right! " + "It took you " + guessCount + " guesses.");
correctGuess = true;
}
}
}
}