Given the following program:.
import java.io.Console; public class Main { public static void main(String[] args){ Console console = System.console(); if (console == null) { System.err.println("No console available."); return;// w w w . j a va2s .c om } String username = console.readLine("Enter user name (%d chars): ", 4); char[] password = console.readPassword("Enter password (%d chars): ", 4); System.out.println("Username: " + username); System.out.println("Password: " + String.valueOf(password)); } }
Assume that the user types the strings java aaaa
and bbbb
cccc
when prompted for the user name and the password, respectively.
Which statement about the program is true?.
Select the one correct answer.
(a) The program will print:/* w w w . j a va 2 s . c o m*/ Username: java Password: bbbb cccc (b) The program will print: Username: java aaaa Password: bbbb (c) The program will print: Username: java aaaa Password: bbbb cccc (d) The program will print: Username: java Password: bbbb
(c)
Both the readLine()
and the readPassword()
method of the Console class return all characters typed on the line.
The arguments of the two methods concern the prompt written to the console.