In Java, it seems that the primitive data type arguments will pass into the method by value. But what if I want to swap the values of two integers.
public static void main(String[] args){
int a = 1;
int b = 2;
swapvalue(a,b);
System.out.println(a);
System.out.println(b);
}
public static void swapValue(int a, int b){
int c = a;
a = b;
b = c;
}
For example, the code above is aimed to swap the values of a and b. In C++ I can pass into the pointers or references to them but I have no idea about how to do this in Java without pointers. How could I make it?