QuestionQ166

Working with Selected Classes from the Java API

Given the following code fragment:

Question Image

What is the output?

  • A S 6
  • B S 5
  • C s-1
  • D w 7
Explanation

trim() does not change the value because there is no leading or trailing whitespace. In "Sweet Sweat", charAt(6) returns S, and indexOf("Sw", 1) returns 6 because "Sw" begins at index 6. Concatenation produces S 6.

Community Discussion

No comments yet. Be the first to start the discussion!