Question: Consider the following methods which appear within the same class. public static void mystery(int[] data) { for (int k = 0; k < data.length; k++)

Consider the following methods which appear within the same class.

public static void mystery(int[] data)

{

for (int k = 0; k < data.length; k++)

{

data[k] = k;

}

}

public static String toString(int[] data)

{ String str = "";

for (int d : data)

{

str = str + d + " ";

}

return str;

}

int[] nums = {1, 2, 7, 3, 5};

mystery(nums);

System.out.println(toString(nums));

  • 1 2 7 3 5

    1 2 7 3 5

  • 1 2 3 4 5

    1 2 3 4 5

  • 0 1 2 3 4

    0 1 2 3 4

  • 12735

    12735

  • Nothing is printed because an ArrayIndexOutOfBoundsException is thrown during the execution of the method mystery.

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!