Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help! The purpose of this exercise is to practice with arrays and static methods in Java /* returns the smallest item found in A

Please help! The purpose of this exercise is to practice with arrays and static methods in Java

/* returns the smallest item found in A */ public static int smallest(int A[]) { return 0; }

/* returns the index of the smallest item found in A */ public static int indexOfSmallest(int A[]) { return 0; }

/* returns the index of the smallest odd number * in A[] or -1 if A[] contains no odd numbers */ public static int indexOfSmallestOdd(int A[]) { return -1; }

/* removes the element in A[] at the given index, * by shifting all remaining elements to the left * if necessary and filling in the right-hand * side with 0s. * * returns the element removed. * * For example, if we call remove(A, 1) * on the array: * * |---+---+----+----+-----+-----+-----+---+---+---| * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | * |---+---+----+----+-----+-----+-----+---+---+---| * | 5 | 9 | 32 | 97 | 101 | 142 | 157 | 0 | 0 | 0 | * |---+---+----+----+-----+-----+-----+---+---+---| * * the array becomes: * * |---+----+----+-----+-----+-----+---+---+---+---| * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | * |---+----+----+-----+-----+-----+---+---+---+---| * | 5 | 32 | 97 | 101 | 142 | 157 | 0 | 0 | 0 | 0 | * |---+----+----+-----+-----+-----+---+---+---+---| * * * and we return the value 9. * * It is up to the caller to make sure that the * index passed to the function is valid. * */ public static int remove(int A[], int index) { return 0; }

public static int[] chunk(int A[], int s, int e) { return null; }

/* returns a new array consisting of the same elements in * A[] repeated numTimes * * for example, if A[] refers to the array: * * |----+----+----| * | 0 | 1 | 2 | * |----+----+----| * | 11 | 22 | 33 | * |----+----+----| * * and numTimes is 3, the function returns: * * |----+----+----+----+----+----+----+----+----| * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | * |----+----+----+----+----+----+----+----+----| * | 11 | 11 | 11 | 22 | 22 | 22 | 33 | 33 | 33 | * |----+----+----+----+----+----+----+----+----| * * * if numTimes <=1, the method returns a copy of A[] * */ public static int[] repeat(int A[], int numTimes) { return null; }

/* reverses the ordering of the elements of each * row of the two-dimensionl array to which A refers. * * For example, if A refers to the array: * * * |----+----+----| * | 10 | 20 | 30 | * |----+----+----+----| * | 40 | 50 | 60 | 70 | * |----+----+----+----| * | 80 | 90 | * |----+----+ * * * the method returns: * * |----+----+----+ * | 30 | 20 | 10 | * |----+----+----+----| * | 70 | 60 | 50 | 40 | * |----+----+----+----| * | 90 | 80 | * |----+----+ * * */ public static void reverseAll(int A[][]) { }

/* scores contains a collection of quiz grades ranging * from 0 to maxScore inclusive. The method returns * a new array where the value at index i is the number * of times that grade i appeared in scores. * * For example, if scores refers to the array: * |---+---+---+----+---+---+---+---+---+---+----+----+----+----+----| * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | * |---+---+---+----+---+---+---+---+---+---+----+----+----+----+----| * | 9 | 3 | 8 | 10 | 7 | 9 | 8 | 9 | 7 | 6 | 8 | 7 | 8 | 9 | 6 | * |---+---+---+----+---+---+---+---+---+---+----+----+----+----+----| * * The method returns the array: * |---+---+---+---+---+---+---+---+---+---+----| * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | * |---+---+---+---+---+---+---+---+---+---+----| * | 0 | 0 | 0 | 1 | 0 | 0 | 2 | 3 | 4 | 4 | 1 | * |---+---+---+---+---+---+---+---+---+---+----| * * */ public static int[] counts(int scores[], int maxScore) { return null; }

/* Extra credit: * * Returns a new array consisting of all of the * elements of A, but with no duplicates. For example, * if A[] is {10,20,5,32,5,10,9,32,8}, the method returns * the array {10,20,5,32,9,8} */ public static int[] uniques(int A[]) { return null; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions