Given the code fragment:
What is the result?
Given the code fragment:
What is the result?
C
Answer is A. Because String str is "Sweet Sweat" not "Sweet sweat" String str="Sweet Sweat"; String str2=str.trim().charAt(6)+" " + str.indexOf("Sw",1); System.out.println(str2); // S 6
Answer is A. S 6
Answer is A.
The answer is the letter C, it is a little complicated but analyzing the code we managed to answer the question ignoring the difficult part. Looking at "str.indexOf("Sw",1)" we can see that it wants to know what is the position of the first "Sw" that appears in the String content and we can see that it is at position 1. The only alternative that prints the 1 in the second position of the string "str2" is the C option.
A is correct, tested.