Program 1:
import java.io.Console;
public class java86
{
public static void main(String[] args)
{
Console console = System.console();
if(console == null)
{
System.out.println("Console is not available to current JVM process");
return;
}
else
{
String userName = console.readLine("Enter the username: ");
System.out.println("Entered username: " + userName);
}
}
}
Output:
Program 2:
import java.io.Console;
public class java86
{
public static void main(String[] args)
{
Console console = System.console();
if(console == null)
{
System.out.println("Console is not available to current JVM process");
return;
}
char[] password = console.readPassword("Enter the password: ");
// System.out.println("Entered password: " + new String(password));
console.printf("Entered password: " + new String(password));
}
}
Output:
No comments:
Post a Comment