-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSupplierExample2.java
More file actions
31 lines (24 loc) · 896 Bytes
/
SupplierExample2.java
File metadata and controls
31 lines (24 loc) · 896 Bytes
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
package predefined_functional_interfaces.supplier;
/*
* Example program to generate 8 digit random password
*/
import java.util.function.Supplier;
public class SupplierExample2 {
static Supplier<Integer> randomIntSupplier = () -> (int)(Math.random()*10);
private static final String symbols="ABCDEFGHIJKLMNOPQRSTUVWXYZ#$@";
static Supplier<Character> randomCharSupplier = () -> symbols.charAt((int)(Math.random()*29));
public static void main(String[] args) {
StringBuilder password = new StringBuilder();
for(int i = 1; i<=8; i++){
if(i%2==0)
password.append(randomIntSupplier.get());
else
password.append(randomCharSupplier.get());
}
System.out.println("Generated Password: "+ password);
}
}
/*
* Output: (will change for each execution)
* Generated Password: U7X2G1B0
*/