For each of the methods echo1, echo2, ..., echo4 shown below, add exactly one line of Java code immediately below the comment “// Your code here:” so that the method produces the same output that echo0 produces for a given input. Do not make any other changes to the code.
public class EchoArgs {
public static void echo0(String[] strings) {
String s;
int n = strings.length;
int i = -1;
while (++i < n) {
s = strings[i];
System.out.print(s);
}
}
public static void echo1(String[] strings) {
String s = "";
int n = strings.length;
int i = 0;
while (i < n) {
// Your code here:
s = strings[i];
System.out.print(s);
i++;
}
}
public static void echo2(String[] strings) {
String s = "";
int n = strings.length;
for (int i = 0; i < n; i++) {
// Your code here:
s += strings[i];
}
System.out.print(s);
}
public static void echo3(String[] strings) {
String args = "";
for (String s : strings) {
// Your code here:
args += s;
}
System.out.print(args);
}
public static void echo4(String[] strings) {
String s = "";
int n = strings.length;
int i = 0;
while (i++ < n) {
// Your code here:
s = strings[i-1];
System.out.print(s);
}
}
public static void main(String[] args) {
echo0(args);
echo1(args);
echo2(args);
echo3(args);
echo4(args);
}
}