Question: Take in any integer array perform several operations on that array. Determine if the values in array are all going up, if the values in
Take in any integer array perform several operations on that array. Determine if the values in array are all going up, if the values in the array are all going down, and return an array that contains a set number of values greater than a particular value.
* An array that is going up will contain values that increase. [1,2,3,4,5] is going up. [1,2,3,0,8] is not going up.
* An array that is going down will contain values that decrease. [5,4,3,2,1] is going down. [5,4,9,1,0] is not going down.
Starter code
public class ArrayFunHouseTwo {
/** * Return true if all numbers in numArray are in increasing order. *
[1,2,6,9,23] returns true.
[1,2,2,9] returns false.
[9, 11, 13, 8] returns false.
/** * Return true if all numbers in numArray are in decreasing order. *
[31,12,6,2,1] returns true.
[9,2,2,1] returns false.
[31, 20, 10, 15, 9] returns false.
/** * Return an array that contains the first count values that are larger than * x. If there are not enough values to fill the returned array, then * the array is zero filled. *
[1,2,3,4,5,6,7,8,9,10,11,6],3,5 would return [6,7,8].
[1,2,3,4,5,6,7,8,9,10,11,6],3,10 would return [11,0,0].
Sample Data :
[1,2,3,4,5,6,7,8,9,10]
[1,2,2,4]
[1,2,3,9,11,20,30]
[9,8,7,6,5,4,3,2,0,-2]
[3,6,9,12,15,18,21,23,19,17,15,13,11,10,9,6,3,2,1,0]
Sample Output :
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
is going Up? true
[1, 2, 2, 4 ]
is going Up? false
[1, 2, 3, 9, 11, 20, 30]
is going Up? true
[9, 8, 7, 6, 5, 4, 3, 2, 0, -2]
is going Up? false
[3, 6, 9, 12, 15, 18, 21, 23, 19, 17, 15, 13, 11, 10, 9, 6, 3, 2, 1, 0]
is going Up? false
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
is going Down? false
[1, 2, 3, 9, 11, 20, 30]
is going Down? false
[9, 8, 7, 6, 5, 4, 3, 2, 0, -2]
is going Down? true
[3, 6, 9, 12, 15, 18, 21, 23, 19, 17, 15, 13, 11, 10, 9, 6, 3, 2, 1, 0]
is going Down? false
[3, 6, 9, 12, 15, 18, 21, 23, 19, 17, 15, 13, 11, 10, 9, 6, 3, 2, 1, 0]
first 7 values greater than 9 [12, 15, 18, 21, 23, 19, 17]
first 5 values greater than 15 [18, 21, 23, 19, 17]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
