Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

If you want to write a method that takes an array of 5 integers and returns a do

ID: 3837618 • Letter: I

Question

If you want to write a method that takes an array of 5 integers and returns a double, which of the following method declarations is valid in Java: private static int myMethod(int[S] arr) public static double[] my Method(int arr) public static double[5] myMethod(int arr[]) public static double _myMethod _(int[] arr) What is the output of running the main in the following program? Assume that the code compiles successfully. Public static void main (String[] args) { doSomething 5); public static int doSomething (int a) { if a % 2 - 1) { switch (a) { case 5: a = a + 2; case 6: a++; return a; case 4: a = a - 2; case 3 a * = 10; break; default: a --; }//end of switch case } a = a + 10; System.out, println ("My a-" + a); return a; } My a = 18 My a=10 My a=90 None of the above is correct Given the following declaration: int [] []stuff; Which of the following statements constructs an array with 4 rows and 7 columns and assigns its reference to stuff? stuff new stuff[7][4]. stuff new int [4][7] stuff = new int [7] [4]; stuff int[7][4];

Explanation / Answer

1. D. public static double _myMethod_(int[] arr)

One double value is what we need to return. int[] arr takes array with any number of elements

2. D. None of the above is correct

a%2 = 5%2 = 1

case 5 will execute

case 6 will execute since there is no break condition in case 5 and it returns there itself.

3. B. stuff = new int [4][7];

int [][]; first one is for rows and second is for columns