Data (and return variable): int []array A = (4, 7, 8, 9, 3); int [] array B = (6
ID: 3821129 • Letter: D
Question
Data (and return variable): int []array A = (4, 7, 8, 9, 3); int [] array B = (6, 6, 3, 5, 4, 4, 7, 8, 2, 1, 3, 8, 11, 4, 2, 1); int [] result; Calls to: result = countOs(arrayA, 'u'); System.out.printf("Result 5a = %d ", result); System.out.println(); result = countOs(arrayA, 'd'); System.out.printf("Result 5b = %d ", result); System.out.println(); result = countOs(arrayA, 'u'); System.out.printf("Result 5c = %d ", result); System.out.println(); result = countOs(arrayA, 'd'); System.out.printf("Result 5d = %d ", result); System.out.println(); result = countOs(arrayA, 'e'); System.out.printf("Result 5e = %d ", result); Code of countOs: private static int countOs(int [] array, char uDE) {int count; int indx; int len = array.length; count = 0; for(indx = 0; indx array[indx]) count++; else if (uDE == 'd' && array[indx + 1]Explanation / Answer
result=countOs(arrayA,'u');
System.out.printf("Result 5a=%d ",result); //Result 5a=3
System.out.println();
result=countOs(arrayA,'d');
System.out.printf("Result 5b=%d ",result); //Result 5b=1
System.out.println();
result=countOs(arrayB,'u');
System.out.printf("Result 5c=%d ",result); //Result 5c=6
System.out.println();
result=countOs(arrayB,'d');
System.out.printf("Result 5d=%d ",result); //Result 5d=7
System.out.println();
result=countOs(arrayB,'e');
System.out.printf("Result 5e=%d ",result); //Result 5e=2
System.out.println();
_______________________
if(uDE=='u' && array[indx+1] > array[indx])
count++;
//Here we are counting if character is equal to 'u' and every even place elements(2 nd element,4th element,6th element...) is greater than odd places elements(1st element,3rd element,5th element) in the array.
______________________
if (uDE=='d' && array[indx+1] < array[indx])
count++;
//Here we are counting if character is equal to 'd' and every even place elements(2 nd element,4th element,6th element...) is less than odd places elements(1st element,3rd element,5th element) in the array.
_______________________
if (uDE=='e' && array[indx+1] == array[indx])
count++;
//Here we are counting if character is equal to 'e' and every even place elements(2 nd element,4th element,6th element...) is equal to odd places elements(1st element,3rd element,5th element) in the array.
________________________
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.