MatiasMerkuri
12/27/2018 - 4:47 PM

Arrays In Methods

ARRAYS IN METHODS

 // Creating an array with the initializer
        int matias[] = {3, 4, 5, 6, 7};

        // Passing the array to the method **CHANGE**
        change(matias);


        // Printing the result of the for loop on the **CHANGE** method to the terminal with the enhanced for loop
        for (int y: matias){
            System.out.println(y);
        }
    }

    // Creating a new method
    // and defining the array in the parameters
    public static void change(int x[]){

        // For loop to take each of the values on the array and add 5 to it
        for (int counter = 0; counter < x.length; counter++) {
            x[counter] += 5;
        }