File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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 1717import java .util .Stack ;
1818import java .util .ArrayList ;
1919
20- class nested_brackets {
20+ class BalancedBrackets {
2121
2222 static boolean is_balanced (char [] S ) {
2323 Stack <Character > stack = new Stack <>();
@@ -26,7 +26,6 @@ static boolean is_balanced(char[] S) {
2626 if (S [i ] == '(' || S [i ] == '{' || S [i ] == '[' ) {
2727 stack .push (S [i ]);
2828 } else if (stack .size () > 0 ) {
29- // pair = (stack.lastElement() + S[i]);
3029 if (!pair .equals ("[]" ) && !pair .equals ("()" ) && !pair .equals ("{}" )) {
3130 return false ;
3231 }
You can’t perform that action at this time.
0 commit comments