Advertisement
Console c= System.console();
Methods | Description |
---|---|
void flush() | This method flushes the buffered output to the console. |
Console format(String frmtSt, Object... args) | This method writes the args to the console using format string, frmtSt. |
Console printf(String frmtSt, Object... args) | This method writes the args to the console using format string, frmtSt. |
Console printf(String frmtSt, Object... args) | This method writes the args to the console using format string, frmtSt. |
String readLine() | This method reads a line of String entered by the user at the console. A line of String ends when user presses Enter. |
String readLine(String frmtSt, Object...args) | This method writes the args to the console using format string, frmtSt, and then this method reads a line of String entered by the user at ths console. |
char[] readPassword() | This method reads a password entered by the user without echoing it on the user screen. The input stops when a user presses Enter at the console. |
char[] readPassword(String frmtSt, Object...args) | This method writes the args to the console using format string, frmtSt, and then it this method reads a password entered by the user
without echoing it on the user screen. Input stops when a user presses Enter. |
Advertisement
// Java - Program to display Console class.
import java.io.*;
class A
{
public static void main(String... ar)
{
//Calling the static console() method of System class, which returns a reference to Console
Console c = System.console();
char[] pwd;
c.format("Enter your details - \n"); // Note1
String str = c.readLine("Enter your name "); // Note2
pwd =c.readPassword("Enter your password "); // Note3
c.printf("Your details are - \n");
c.format("Your username is : %s \n", str); // Note4
c.printf("Your password is : ");
//Displaying password with for-each, one char a time
for(char ch : pwd)
c.printf("%c", ch); // Note5
}
}
Enter your details -
Enter your username SkyGazer
Enter your password
Your details are -
Your username is : SkyGazer
Your password is : abcdef
Argument Type | Format String |
---|---|
String | %s |
char | %c |
int | %d |
boolean | %b |
float | %f |
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement