nerdexam
Oracle

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…

Data Types and Operators

Question

Given the code fragment: String inputFromConsole = " betaTEST "; String cleanedInput; cleanedInput = inputFromConsole.toUpperCase(); cleanedInput = cleanedInput.trim(); System.out.println("[" + cleanedInput + "]"); What is the result?

Options

  • A[ BETATEST ]
  • B[BetaTest]
  • C[BETATEST]
  • D[BETATEST]

How the community answered

(55 responses)
  • A
    2% (1)
  • B
    7% (4)
  • C
    2% (1)
  • D
    89% (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 if trim() 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 think toUpperCase() 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

#String methods#String manipulation#toUpperCase#trim

Community Discussion

No community discussion yet for this question.

Full 1Z0-811 Practice