0
import java.util.*;

public class Main {
    private static int call(int n) {
        n = n - 1;
        return n;
    }
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = 5;
        call(n);
        System.out.println(n);//output is still 5;
    }
}

how to change the value of n using call method? I did using void on call method like we use for integer array but that is also not working.

Deepak Silver
  • 27
  • 1
  • 3
  • 1
    "how to change the value of n using call method?" If you want to change the value of `n`, you need to explicitly assign the result of `call(n)` to it, like this: `n = call(n);` There is no other way. – Stephen C Aug 29 '21 at 05:14
  • What would you expect to happen if you wrote `call(5)`? – Louis Wasserman Aug 29 '21 at 05:51

0 Answers0