Java String Method Analysis
Consider the following processWords method. Assume that its String parameters, word1 and word2, each have a length of two or more.
public void processWords(String word1, String word2) {
String str1 = word1.substring(0, 2);
String str2 = word2.substring(word2.length() - 1);
String result = str2 + str1;
System.out.println(result.indexOf(str2));
}
Which of the following best describes the value printed when processWords is called?
A
A substring containing the last character of word2 is printed.
B
The value result.length() - 1 is printed.
C
The value 0 is always printed.
D
A substring containing the last two characters of word2 is printed.
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | varunrajaram1 | 2 | 2 | 0m 00s | 200 |
| #2 | l.alzahrani04 | 1 | 1 | 0m 00s | 100 |
| #3 | avantikaabaid10901 | 1 | 1 | 0m 00s | 100 |
| #4 | sgarv2513 | 1 | 1 | 0m 00s | 100 |
| #5 | sailajavadlamani33 | 1 | 4 | 0m 00s | 70 |
| #6 | waynechen0110 | 1 | 7 | 0m 00s | 40 |
| #7 | kshiva2009m | 1 | 1 | 1m 10s | 30 |
| #8 | abdulboriyxon.bositxonov.2008 | 1 | 1 | 1m 20s | 20 |
| #9 | florianfertz2000 | 1 | 2 | 1m 11s | 19 |
| #10 | y.seong2027 | 0 | 1 | 0m 03s | -13 |
APFIVE