Java String Method Analysis
Which of the following best describes the value printed when processWords is called?
Consider the processWords method. Assume that each of its two parameters is a String of length 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
The value result.length() - 1 is printed.
B
The value 0 is always printed.
C
A substring containing the last character of word2 is printed.
D
A substring containing the last two characters of word2 is printed.
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | varunrajaram1 | 2 | 2 | 0m 00s | 200 |
| #2 | malaikashahid501 | 2 | 2 | 0m 14s | 186 |
| #3 | sgarv2513 | 1 | 1 | 0m 00s | 100 |
| #4 | avantikaabaid10901 | 1 | 1 | 0m 00s | 100 |
| #5 | l.alzahrani04 | 1 | 1 | 0m 00s | 100 |
| #6 | testsss1 | 1 | 1 | 0m 02s | 98 |
| #7 | liuwilliam072410 | 1 | 1 | 0m 17s | 83 |
| #8 | sailajavadlamani33 | 1 | 4 | 0m 00s | 70 |
| #9 | aaaa1 | 1 | 3 | 0m 14s | 66 |
| #10 | kazvin.tjakradinata | 1 | 1 | 0m 35s | 65 |
Items per page:
10
1 – 10 of 45
APFIVE