-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPassword.java
More file actions
28 lines (23 loc) · 854 Bytes
/
Password.java
File metadata and controls
28 lines (23 loc) · 854 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
import java.util.Random;
import java.util.Scanner;
public class Password {
public static void main(String...args) {
Scanner scanner = new Scanner (System.in);
int guess = 0;
int count = 0;
Random r = new Random();
int password = r.nextInt(100);
while (guess != password) {
count++;
System.out.println("Enter the password >:|");
guess = scanner.nextInt();
if (guess < password) {
System.out.println("The number you guessed is too low!");}
else if (guess > password) {
System.out.println("The number you guessed is too high!");
}
}
System.out.println("CHOP SHOP");
System.out.println("You have guessed " + count + " times!" );
}
}