PRACTICE • LEARN • GROW
Module 3: Input and Output - Final Quiz MCQs
Solve topic-wise placement questions and improve your skills.
Module 3: Input and Output - Final Quiz Progress
0 of 11 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
What is the primary operational difference between
System.out.print() and System.out.println()?
A.
print() outputs text in red while println() outputs in green
B.
print() leaves the console cursor on the same line, whereas println() appends a newline character moving the cursor to the next line
C.
println() only accepts String literals while print() accepts numbers
D.
print() flushes the buffer immediately while println() never flushes
Explanation & Key
Correct Answer:
2
What is printed by this formatted output call?
String product = "Pen";
double price = 4.5;
System.out.printf("%s costs $%.2f", product, price);
A.
Pen costs $4.5
B.
Pen costs $4.50
C.
Pen costs $%.2f
D.
Compilation error: mismatched format specifiers
Explanation & Key
Correct Answer:
3
What bug occurs in the following code when a user enters 25 followed by pressing Enter, and then intends to type their name?
Scanner sc = new Scanner(System.in);
System.out.print("Enter age: ");
int age = sc.nextInt();
System.out.print("Enter name: ");
String name = sc.nextLine();
A.
age throws InputMismatchException
B.
sc.nextLine() immediately consumes the leftover newline ('\n') from nextInt(), causing name to be set to an empty string without prompting the user
C.
The code enters an infinite loop waiting for keyboard input
D.
System.in closes prematurely
Explanation & Key
Correct Answer:
4
Why is
BufferedReader significantly faster than Scanner for reading large volumes of input in competitive programming?
A.
BufferedReader bypasses the Java Virtual Machine and reads directly from hardware
B.
BufferedReader has a large default buffer (8KB) and reads raw text lines without parsing overhead, whereas Scanner parses regex tokens with a tiny 1KB buffer
C.
BufferedReader compiles to native machine code ahead of time
D.
Scanner cannot read input from files
Explanation & Key
Correct Answer:
5
Which class must be imported to read keyboard input using
Scanner?
A.
java.io.Scanner
B.
java.util.Scanner
C.
java.lang.Scanner
D.
java.system.Scanner
Explanation & Key
Correct Answer:
6
What type of data stream is represented by
System.in in Java?
A.
java.io.Reader (character stream)
B.
java.io.InputStream (raw byte stream connected to standard input)
C.
java.util.Scanner stream
D.
java.nio.file.Path stream
Explanation & Key
Correct Answer:
7
What happens if you invoke
sc.close() on a Scanner created with new Scanner(System.in)?
A.
Only the Scanner instance is closed; System.in remains fully open
B.
The Scanner closes the underlying System.in stream, preventing any further console input for the entire remainder of the JVM session
C.
Throws an UnsupportedOperationException
D.
The terminal window automatically closes
Explanation & Key
Correct Answer:
8
What is printed by this formatted printf call using zero-padding and explicit sign flags?
int num = 42;
System.out.printf("%+05d", num);
A.
42
B.
+0042
C.
00042
D.
+4200
Explanation & Key
Correct Answer:
9
What will be printed by the following Scanner tokenization snippet?
Scanner sc = new Scanner("Java 17\nReadyToGo Platform");
System.out.print(sc.next() + " | ");
System.out.print(sc.nextLine());
A.
Java | 17
B.
Java | ReadyToGo Platform
C.
Java 17 | ReadyToGo Platform
D.
Java | 17 ReadyToGo Platform
Explanation & Key
Correct Answer:
10
Which checked exception must be declared or handled when reading input via
BufferedReader.readLine()?
A.
java.lang.NullPointerException
B.
java.io.IOException
C.
java.util.InputMismatchException
D.
java.lang.IndexOutOfBoundsException
Explanation & Key
Correct Answer:
11
Why might outputs from
System.out.println() and System.err.println() appear interleaved or out of chronological order when executed sequentially in a terminal?
A.
System.err runs on a separate background daemon thread automatically
B.
System.out and System.err represent two separate OS streams; System.out is buffered while System.err is unbuffered, leading to non-synchronized console flushes
C.
System.err is executed only during JVM shutdown
D.
System.out has lower priority than CPU interrupts
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong