Arrays
More skills
Parameters
A general syntax to declare an array as a formal parameter
dataType[] arrayName
Declaring Arrays as Formal Parameters to Methods
public static void arraysAsFormalParameter(int[] listA, double[] listB, int num) { //... } int[] intList = new int[10]; double[] doubleNumList = new double[15]; int number; arraysAsFormalParameter(intList, doubleNumList, number);
Passing elements of arrays as Parameters to Methods
Individual elements of the arrays can be passed as parameters to methods.
int[] list = {2,3,5}; public static int sumNum(int firstNum, int secondNum) { return firstNum+secondNum; } System.out.println("Sum = " + sumNum(list[0], list[1]));