Question: Consider the following methods: public static double average(int[] nums) { int sum = 0; for (int i = 0; i < nums.length; i++) { sum
Consider the following methods:
public static double average(int[] nums) { int sum = 0; for (int i = 0; i < nums.length; i++)
{
sum += nums[i]; }
return sum / nums.length;
} //average
public static int[] mystery(String[] a) { int[] temp = new int[a.length]; for (int i = 0; i < a.length; i++) {
temp[i] = a[i].length(); }
return temp; } //mystery
What is output by running the following?
String[] spelling = {"orange", "green", "red", "blue", "yellow"}; System.out.println(average(mystery(spelling)));
-
5
-
4.8
-
4.0
-
Error - you cannot average Strings
-
24
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
