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

In Java, a function called allOf to StdIntArray which returns true if all the ar

ID: 3745849 • Letter: I

Question

In Java,

a function called allOf to StdIntArray which returns true if all the array or sub-array elements match the given value, and false otherwise.There should be two versions, one that works with the entire array, and one that works with sub-array defined by a half-open range. The signatures should be

public static boolean allOf(int a[], int value)

public static boolean allOf(int a[], int lo, int hi, int value)

The version that works with the entire array should call the sub-array version.

Explanation / Answer

public static boolean allOf(int a[], int value) { return allOf(a, 0, a.length, value); } public static boolean allOf(int a[], int lo, int hi, int value) { if (lo >= hi) { return true; } else if (a[lo] != value) { return false; } else { return allOf(a, lo+1, hi, value); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote