Question: 1.) The method copy should have a new array of the same size as nums with all the same values in the same order and

1.) The method copy should have a new array of the same size as nums with all the same values in the same order and return it.

public class ArrayFun

{

  // Assume this instance variable is initialized with value in the constructor

  private int[] nums;


 

  // return a copy of nums

  public int[] copy()

  { /* implemented in part 1 */ }


 

  // return the maximum value in nums

  public int getMax()

  { /* implemented in part 2 */ }



 

}


 

 

 


 

2.) The method getMax should return the highest value in the array nums.  If there is not at least one value in the array, this method should return -1.

nums (before)return
[2, 4, 6]6
[3, 4, 5, 5]5
[4, 5]5
[]-1

 

 

 

 

 

 

3.) How to write a method called makeEvenArray that takes an int parameter, n, and creates an array with n int values. It returns that array populated with the first n even integers starting from 0. For example, if n = 5 then the array will have the values {0, 2, 4, 6, 8}

 

 

 

4.) How to write a method called countSmaller that takes an array of ints as a parameter and returns how many elements of that array are less than the value stored in val.   For example, if int[] x = {4, 6, 8}, countSmaller(x, 6) would return 1 because only one element of x, 4, is less than 6.

Step by Step Solution

3.47 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

ArrayFunjava public class ArrayFun Assume this instance variable is initialized with value in the co... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!