Implement this function in java : public static int [] generateRandomArr(int length, int sorted){ } The first parameter: an non-negative integer, that specifies the size (length) of the array that is...


Implement this function in java :<br>public static int [] generateRandomArr(int length, int sorted){ }<br>The first parameter: an non-negative integer, that specifies the size (length) of the array that is created.<br>The second parameter: an integer in the range [0, 100], inclusive, that specifies the degree to which the array's<br>contents are sorted.<br>If sorted=0 , the contents of the array should be in perfect reverse order.<br>If sorted=100, the contents of the array be 100% sorted.<br>Any value intermediate should result in an array that has approximately that % of its entries that are sorted.<br>Hint : You can approximate this by starting with a perfectly sorted array;<br>select at random (100%- sorted%) of the entries in the array, and override those values with a random integer<br>greater than the value the ordered array's entries. The exception to this is when sorted=100 , in which case the<br>array's contents must be perfectly sorted.<br>For example, the following length and sorted parameters might result in the indicated arrays:<br>1. generateRandomArr(5, 0)<br>2. generateRandomArr(5, 0)<br>3. generateRandomArr(5, 100)<br>4. generateRandomArr(5, 100)<br>5. generateRandomArr(5, 60)<br>6. generateRandomArr(5, 20) -<br>--> [ 34 23 3 2 1]<br>[6 5 4 3 2]<br>--> [1 45 52 80 90 ]<br>-> [1 2 3 4 5]<br>->[1 24 78 4 5] /l/manipulation of array in no.4<br>->[ 96 110 123 80 712] //manipulation of array in no.3<br>

Extracted text: Implement this function in java : public static int [] generateRandomArr(int length, int sorted){ } The first parameter: an non-negative integer, that specifies the size (length) of the array that is created. The second parameter: an integer in the range [0, 100], inclusive, that specifies the degree to which the array's contents are sorted. If sorted=0 , the contents of the array should be in perfect reverse order. If sorted=100, the contents of the array be 100% sorted. Any value intermediate should result in an array that has approximately that % of its entries that are sorted. Hint : You can approximate this by starting with a perfectly sorted array; select at random (100%- sorted%) of the entries in the array, and override those values with a random integer greater than the value the ordered array's entries. The exception to this is when sorted=100 , in which case the array's contents must be perfectly sorted. For example, the following length and sorted parameters might result in the indicated arrays: 1. generateRandomArr(5, 0) 2. generateRandomArr(5, 0) 3. generateRandomArr(5, 100) 4. generateRandomArr(5, 100) 5. generateRandomArr(5, 60) 6. generateRandomArr(5, 20) - --> [ 34 23 3 2 1] [6 5 4 3 2] --> [1 45 52 80 90 ] -> [1 2 3 4 5] ->[1 24 78 4 5] /l/manipulation of array in no.4 ->[ 96 110 123 80 712] //manipulation of array in no.3
Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here