O'Reilly logo

Java Programming for Beginners by Mark Lassoff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using variables in the program

To see this, let's create a brand new method, and in its declaration, we'll have it the same as our existing magic method. However, instead of taking a single integer as input, we'll provide it as input in the integer array:

package advancedmethods;public class AdvancedMethods {    public static void main(String[] args) {        int[] x = 5;        magic(x);        System.out.println("main: " + x);    }     public static void magic(int input)    {        input += 10;    }    public static void magic(int[] input)    {        input += 10;    }}

Remember that our array will be named as a single variable, so all we need to do to let Java know that we'd like to pass an array to the function is inform it that the variable being given is an array of a certain type. You'll ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required