operate.printRange( ar1, 3, 3);
This will print out element 3 of the array, the value 5.
Here is the ArrayOps
class, now including
with a new method.
This new method adds up all the elements in
an array.
Here is how the method might be used in main()
:
class ArrayDemo { public static void main ( String[] args ) { ArrayOps operate = new ArrayOps(); int[] ar1 = { -20, 19, 1, 5, -1, 27, 19, 5 } ; System.out.println("The sum of elements is: " + operate.sumElements( ar1 ) ); } }
The declaration of the method says that it expects an array of
int
as a parameter, and that it will return an
int
back to the caller when it is done:
int sumElements ( int[] nums )
Fill in the blanks of the sumElements()
method.