If the user types fido when prompted for a password, and then responds bob when prompted for a name, what is the result?

Given that c is a reference to a valid java.io.Console object, and:

11. String pw = c.readPassword(“%s”, “pw: “);
12. System.out.println(“got ” + pw);
13. String name = c.readLine(“%s”, “name: “);
14. System.out.println(” got “, name);

If the user types fido when prompted for a password, and then responds bob when prompted for a name, what is the result?

Given that c is a reference to a valid java.io.Console object, and:

11. String pw = c.readPassword(“%s”, “pw: “);
12. System.out.println(“got ” + pw);
13. String name = c.readLine(“%s”, “name: “);
14. System.out.println(” got “, name);

If the user types fido when prompted for a password, and then responds bob when prompted for a name, what is the result?

A.
pw: got fido
name: bob got bob

B.
pw: fido got fido
name: bob got bob

C.
pw: got fido
name: bob got bob

D.
pw: fido got fido
name: bob got bob

E.
Compilation fails.

F.
An exception is thrown at runtime.

Explanation:
Main.java:14: cannot find symbol
symbol : method println(java.lang.String,java.lang.String)
location: class java.io.PrintStream
System.out.println(” got “, name);
^
1 error



Leave a Reply 2

Your email address will not be published. Required fields are marked *


Regina

Regina

c.readPassword(ā€œ%sā€, ā€œpw: ā€œ); will return a char[], not a String.