-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathMain.java
More file actions
32 lines (27 loc) · 921 Bytes
/
Main.java
File metadata and controls
32 lines (27 loc) · 921 Bytes
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
/**
* Created by iyasuwatts on 10/17/17.
*/
import java.util.Scanner;
import java.util.Random;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Guess a number between 1 - 25: ");
Random randNum = new Random();
int answer = randNum.nextInt(25) + 1;
int count = 0;
while (true) {
int userInput = input.nextInt();
count ++;
if (userInput > answer) {
System.out.println("Too large, try again: ");
} else if (userInput < answer) {
System.out.println("Too Small, try again: ");
} else {
System.out.println("That is the correct number!!");
System.out.println("You guessed: " + count + " times before guessing right");
break;
}
}
}
}