Returning methods code example

Example 1: Returning methods

public class App {
    public static void main(String[] args) 
    {
        int x=3;
        int answer = addFive(x);
        System.out.println("answer is = " + answer);
    }

    private static int addFive(int px) 
    {
        px += 5;
        return px;
    }
}

Example 2: Returning methods

public class App {
    public static void main(String[] args) 
    {
        int x = 3;
        int answer = addFive(x);
        System.out.println("answer is = " + answer);
    }

    private static int addFive(int px) 
    {
        px += 5;
        return px;
    }
}

Example 3: Returning methods

public class App {
    public static void main(String[] args) 
    {
        int x = 3;
        int answer = addFive(x);
        System.out.println("x = " + answer);
    }

    private static int addFive(int px) 
    {
        x += 5;
        return px;
    }
}

Tags:

Java Example