Consider the following Java program:
public class Array {
public static void printArray(int[] x) {
for (int i = 0; i < x.length; i++) // loop to print numbers
System.out.print(x[i] + " ");
System.out.println();
}
public static void main(String[] args) {
int[] a = {12, 23, 34, 45, 56};
int[] b = {4, 1, 2, 5, 3};
printArray(a);
}
}
- What will the program print?
- Add code above that will print the values of the array
b,
using the printArray function.
- Write a new function
multiplyElements
that will multiply all the elements of an array which is its
parameter, and will then return the product, as an
int.
(Write this function in above.)
- Show how to use the function in part c. above to multiply the elements
of the array b
and to print the resulting number (which is 120 in this case).
(Add this also to the above.)