-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathMain.java
More file actions
40 lines (26 loc) · 962 Bytes
/
Main.java
File metadata and controls
40 lines (26 loc) · 962 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
32
33
34
35
36
37
38
39
40
/**
* 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 scan = new Scanner(System.in);
Random rand = new Random();
int randomInt = rand.nextInt(100) + 1;
System.out.print("Guess a number between 1 - 100: ");
int userNumber = 0;
int counter = 0;
while (userNumber != randomInt) {
userNumber = scan.nextInt();
counter += 1;
if (userNumber > randomInt) {
System.out.print("Your guess is too high, guess again: ");
} else if (userNumber < randomInt) {
System.out.print("Your guess is too low, guess again: ");
}
}
System.out.println("Your number " + userNumber + " was the correct guess! You had " + counter + " attempts!");
//System.out.println(userNumber);
}
}