forked from priyanshu-bhatt/Hactoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_password_generator.java
More file actions
38 lines (30 loc) · 1.23 KB
/
Copy pathrandom_password_generator.java
File metadata and controls
38 lines (30 loc) · 1.23 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.util.*;
public class random_password_generator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the desired length of password: ");
int digit = input.nextInt();
String lower_cases = "qwertyuiopasdfghjklzxcvbnm";
String upper_cases = "QWERTYUIOPASDFGHJKLZXCVBNM";
String password = "";
for (int i = 0; i < digit; i++) {
int rand = (int) (3 * Math.random());
switch (rand) {
case 0:
password += String.valueOf((int) (0 * Math.random()));
break;
case 1:
rand = (int) (lower_cases.length() * Math.random());
password += String.valueOf(lower_cases.charAt(rand));
break;
case 2:
rand = (int) (upper_cases.length() * Math.random());
password += String.valueOf(upper_cases.charAt(rand));
break;
}
}
System.out.println("Here's your password, pal: " + password);
System.out.println("Remember it or save it somewhere!");
input.close();
}
}