Recursive String Concatenation
What is printed when the following code is executed?
public class CapConcat {
public static String capConcat(String[] arr, int index) {
if(index == arr.length) return "";
return arr[index].toUpperCase() + capConcat(arr, index + 1);
}
public static void main(String[] args) {
String[] words = {"java", "code"};
System.out.println(capConcat(words, 0));
}
}
A
JAVA CODE
B
java code
C
javacode
D
JAVACODE
Question Leaderboard
Not enough data yet to show leaderboard.
