-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
37 lines (31 loc) · 1.08 KB
/
Main.java
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
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in); // Reading from System.in
System.out.println("Capitalized letters? true / false");
boolean capitalFlag = reader.nextBoolean();
System.out.println("Numbers? true / false");
boolean numberFlag = reader.nextBoolean();
System.out.println("Symbols? true / false");
boolean symbolsFlag = reader.nextBoolean();
System.out.println("Password length?");
int passLength = reader.nextInt();
reader.close();
String alphabet = "abcdefghijklmnopqrstuvwxyz";
if (capitalFlag){
alphabet += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
if (numberFlag){
alphabet += "1234567890";
}
if (symbolsFlag){
alphabet+="!@#$%^&*()_+{}|:<>?";
}
String password = "";
for (int i=0; i<passLength; i++){
Random rand = new Random();
password += alphabet.charAt(rand.nextInt(alphabet.length() + 1)); //Add a random character from the alphabet
}
System.out.println("Password: "+password);
}
}