458,700 views
25 votes
25 votes
Consider the following method:

public static String joinTogether(int num, String[] arr)
{
String result = "";
for (String x : arr)
{
result = result + x.substring(0, num);
}
return result;
}

The following code appears in another method in the same class:
String[] words = {"dragon", "chicken", "gorilla"};
int number = 4;
System.out.println(joinTogether(number, words));

What is printed when the code above is executed?
a. dragonchickengorilla
b. drachigor
c. dragchicgori
d. dragochickgoril
e. There is an error in the program, it does not run

Consider the following method: public static String joinTogether(int num, String[] arr-example-1
User Luddek
by
2.9k points

1 Answer

18 votes
18 votes

Answer: b.

Step-by-step explanation:

User Ayman Nedjmeddine
by
3.0k points