File tree 3 files changed +43
-41
lines changed
3 files changed +43
-41
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .Collections ;
2
+ import java .util .Random ;
3
+ import java .util .List ;
4
+ import java .util .ArrayList ;
5
+
6
+ /*
7
+ Creates a random password from ASCII letters
8
+
9
+ author: AKS1996
10
+ date: 2017-10-22
11
+ */
12
+
13
+ class PasswordGen {
14
+ public static void main (String args []){
15
+ Random random = new Random ();
16
+
17
+ String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
18
+ String lower = "abcdefghijklmnopqrstuvwxyz" ;
19
+ String numbers = "0123456789" ;
20
+ String specialChars = "!@#$%^&*(){}?" ;
21
+
22
+ String allChars = upper +lower +numbers +specialChars ;
23
+
24
+ List <Character > letters = new ArrayList <Character >();
25
+ for (char c :allChars .toCharArray ())
26
+ letters .add (c );
27
+
28
+ // Inbuilt method to randomly shuffle a elements of a list
29
+ Collections .shuffle (letters );
30
+
31
+ int min_length = 8 ;
32
+ int max_length = 16 ;
33
+ String password = "" ;
34
+
35
+ // Note that size of the password is also random
36
+ for (int i = random .nextInt (max_length -min_length ) + min_length ; i >0 ; --i ) {
37
+ password += letters .get (random .nextInt (letters .size ()));
38
+ }
39
+
40
+ System .out .print ("Password: " + password );
41
+ }
42
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 17
17
import java .util .Stack ;
18
18
import java .util .ArrayList ;
19
19
20
- class nested_brackets {
20
+ class BalancedBrackets {
21
21
22
22
static boolean is_balanced (char [] S ) {
23
23
Stack <Character > stack = new Stack <>();
@@ -26,7 +26,6 @@ static boolean is_balanced(char[] S) {
26
26
if (S [i ] == '(' || S [i ] == '{' || S [i ] == '[' ) {
27
27
stack .push (S [i ]);
28
28
} else if (stack .size () > 0 ) {
29
- // pair = (stack.lastElement() + S[i]);
30
29
if (!pair .equals ("[]" ) && !pair .equals ("()" ) && !pair .equals ("{}" )) {
31
30
return false ;
32
31
}
You can’t perform that action at this time.
0 commit comments