CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades

Arrays

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]));
Previous | Parameters | Pass by value | Assignment operators | Sort | Search | Next