-
Notifications
You must be signed in to change notification settings - Fork 1
/
Password.java
48 lines (32 loc) · 1.09 KB
/
Password.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
38
39
40
41
42
43
44
45
46
47
48
import java.io.Console;
public class Password {
public static void main(String[] args) {
Console cnsl = null;
String alpha = null;
try {
// creates a console object
System.out.println("Llllll");
cnsl = System.console();
// if console is not null
if (cnsl != null) {
// read line from the user input
alpha = cnsl.readLine("Name: ");
// prints
System.out.println("Name is: " + alpha);
// read password into the char array
char[] pwd = cnsl.readPassword("Password: ");
// prints
//System.out.println("Password is: "+pwd.length);
for(int i=0;i<pwd.length;i++){
System.out.print(pwd[i]);
}
}
else {
System.out.println("no exec");
}
} catch(Exception ex) {
// if any error occurs
ex.printStackTrace();
}
}
}