Skip to content

Commit 1c34220

Browse files
author
AKS1996
committed
Name and convention changed to Java 8
1 parent cecf806 commit 1c34220

File tree

3 files changed

+43
-41
lines changed

3 files changed

+43
-41
lines changed

Others/PasswordGen.java

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}

Others/password_gen.java

-39
This file was deleted.

Others/nested_brackets.java renamed to data_structures/Stacks/BalancedBrackets.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.util.Stack;
1818
import 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
}

0 commit comments

Comments
 (0)