92.9k views
3 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

1 Answer

4 votes

Answer: b.

Step-by-step explanation:

User Kuba Wasilczyk
by
4.9k points