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: 3836874 • 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[5]arr) public static double[] myMethod(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) { do something (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.
Since we are passing an array of 5 integers and returns a double, declaration should be
public static double _myMethod_(int[] arr)

2. In this problem , the method is called with 5. Since it is odd, it will enter the first if condition. a will be 7
But here 'break' is not used. So, after that the next condition a++ will also be executed and returned from the method
So, nothing will be printed
Answer is D. None of the above option is correct

3. The way to create a 2d matrix in java is

int[][] arr = new int[rows][cols];
So, answer will be stuff = new int[4][7]; (B)