-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathMain.java
More file actions
35 lines (30 loc) · 1.08 KB
/
Main.java
File metadata and controls
35 lines (30 loc) · 1.08 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
import java.util.Scanner;
/**
* Created by iyasuwatts on 10/17/17.
*/
public class Main {
public static void main(String[] args){
Scanner userIn = new Scanner(System.in);
System.out.println("Please enter an integer between 0 and 10");
int userNumber = userIn.nextInt();
int random = (int)(Math.random() * 10);
int count = 1;
do {
if (userNumber > random) {
System.out.println("too large");
} else if (userNumber < random) {
System.out.println("too small");
} else {
System.out.println("invalid entry");
}
Scanner retry = new Scanner(System.in);
System.out.println("Enter a new number");
userNumber = retry.nextInt();
count++;
} while (userNumber != random);
if(userNumber == random) {
System.out.println("correct guess");
}
System.out.println("You guessed " + count + " times");
}
}