Question: Consider the following method public static String joinTogether(int num, String[] arr) { String result = ; for (String x : arr) { result = result

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?

  • dragonchickengorilla

    dragonchickengorilla

  • drachigor

    drachigor

  • dragochickgoril

    dragochickgoril

  • There is an error in the program, it does not run

    There is an error in the program, it does not run

  • dragchicgori

    dragchicgori

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!