Question: 1. Consider the method doTask defined below. public static int doTask (int [] a) int index-0; int soFar 1; int count-1; for(int k 1; kca.length;
1. Consider the method doTask defined below. public static int doTask (int [] a) int index-0; int soFar 1; int count-1; for(int k 1; kca.length; k+ count++ if(count>soFar) soFar count; index-k; else count-1; return alindexl: When the following code segment is executed, Intl] arr-(1, 2, 3, 3, 3, 3, 4, 2, 2, 2, 2,2, 2,2,5,6,6,6,6,6, 6,4,7,8 System.out.printin(do Task(arr)) what is printed to the screen? Why? a. 1 b. 2 c. 6 d. 7 e. 24 2. Assume that the following declarations have been made. intl) A-(1, 2, 3,4, 5, 6, 7,8 intl) B-(4, 5, 6, 7,8) Also, assume that the method printContents is defined with the following header and works as specified in the comment. //Prints the contents of array arr to the screen. public static void printContents(int) arr)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
