Created seaprate method for each functionality
This commit is contained in:
parent
a6929d1cab
commit
e9e98ecc8e
@ -4,12 +4,28 @@ import java.io.Console;
|
|||||||
|
|
||||||
public class ConsoleAndOut {
|
public class ConsoleAndOut {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
try {
|
||||||
|
printConsoleObject();
|
||||||
|
readPasswordFromConsole();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
// Eating NullPointerExcpetion which will occur when this
|
||||||
|
// program will be run from mediums other than console
|
||||||
|
}
|
||||||
|
printSysOut();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void printConsoleObject() {
|
||||||
Console console = System.console();
|
Console console = System.console();
|
||||||
console.writer().print(console);
|
console.writer().print(console);
|
||||||
|
}
|
||||||
char[] password = console.readPassword("Enter password:");
|
|
||||||
|
static void readPasswordFromConsole() {
|
||||||
|
Console console = System.console();
|
||||||
|
char[] password = console.readPassword("Enter password: ");
|
||||||
console.printf(String.valueOf(password));
|
console.printf(String.valueOf(password));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void printSysOut() {
|
||||||
System.out.println(System.out);
|
System.out.println(System.out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user