-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathMain.java
More file actions
45 lines (37 loc) · 1.35 KB
/
Main.java
File metadata and controls
45 lines (37 loc) · 1.35 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
import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Random number = new Random();
int rando = number.nextInt(100) + 1;
int counter = 1;
Scanner input = new Scanner(System.in);
System.out.println("I'm thinking of a number between 1 and 100");
System.out.println("Guess what it is:");
int guess = input.nextInt();
int lastGuess=-1;
while (guess != rando){
if (guess > rando){
lastGuess=guess;
System.out.println("You're guessing too high");
System.out.println("Guess again:");
guess = input.nextInt();
if(lastGuess != guess) {
counter++;
}
}
else if (guess < rando){
lastGuess=guess;
System.out.println("You're guessing too low");
System.out.println("Guess again:");
guess = input.nextInt();
if(lastGuess != guess) {
counter++;
}
}
}
System.out.println("You got it! I was thinking of " + rando + "!");
System.out.println("Winner Winner Chicken Dinner!");
System.out.println("It only took you " + counter + " guesses!");
}
}