1Z0-811 · Question #44
Given the code fragment: String inputFromConsole = " betaTEST "; String cleanedInput; cleanedInput = inputFromConsole.toUpperCase(); cleanedInput = cleanedInput.trim(); System.out.println("[" +…
The correct answer is D. [BETATEST]. Option D ([BETATEST]) is correct because toUpperCase() converts " betaTEST " to " BETATEST " - preserving the surrounding spaces - and then trim() strips those leading and trailing spaces, leaving "BETATEST" wrapped in brackets. Why the distractors fail: A ([ BETATEST ]) would…
Question
Options
- A[ BETATEST ]
- B[BetaTest]
- C[BETATEST]
- D[BETATEST]
How the community answered
(55 responses)- A2% (1)
- B7% (4)
- C2% (1)
- D89% (49)
Explanation
Option D ([BETATEST]) is correct because toUpperCase() converts " betaTEST " to " BETATEST " - preserving the surrounding spaces - and then trim() strips those leading and trailing spaces, leaving "BETATEST" wrapped in brackets.
Why the distractors fail:
- A (
[ BETATEST ]) would be the result iftrim()were never called - the spaces from the original string remain. - B (
[BetaTest]) reflects neither method correctly; the casing is neither original nor fully uppercase. - C appears visually identical to D in this rendering, but the intended distractor likely represents
[ BETATEST ]with spaces, catching students who thinktoUpperCase()automatically trims whitespace.
Memory tip: Think of the methods as a two-step car wash - toUpperCase() paints everything the same color (uppercase), but doesn't touch the dirt on the bumpers (spaces); trim() is the final rinse that removes those edge spaces. Order matters: both steps are needed, and each does only its own job.
Topics
Community Discussion
No community discussion yet for this question.