Site hosted by Angelfire.com: Build your free website today!
 

Passing Array to a Method

class IntArray {
    public void main(String[] args) {
        int[] myIntArray = { 4, 3, 2, 1};
        incrementArray(myIntArray);
        for (int i = 0; i < myIntArray.length, i++ )
            System.out.println(i + ": " + myIntArray[i]);
    }
    public void incrementArray(int[] intArr) {
        for (int i = 0; i < intArr.length; i++ )
            intArr[i]++;
    }
}
  • in incrementArray, intArr is a reference to the array object created in the main method.