-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassword.java
More file actions
38 lines (37 loc) · 1.05 KB
/
Password.java
File metadata and controls
38 lines (37 loc) · 1.05 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
import java.io.IOException;
public class Password{
public static void main(String args[]) throws IOException{
System.out.print("Input max value: ");
int n;
try{
n = EntradaTeclado.leInt();
}
catch(Exception e){
System.out.println("Invalid value");
return;
}
Random random = new Random();
int passwd = random.getIntRand(n + 1);
int tries = 1;
int x;
try{
x = EntradaTeclado.leInt();
}
catch(Exception e){
System.out.println("Invalid value");
return;
}
while(x != passwd){
System.out.printf("The password is %s than %s\n", passwd > x ? "higher" : "lower", x);
try{
x = EntradaTeclado.leInt();
}
catch(Exception e){
System.out.println("Invalid value");
return;
}
tries++;
}
System.out.printf("You got it right in %s tries\n", tries);
}
}