i started learning Java some days ago. I have some experience with C++ and this is why I'm used to pointers, which would make this much easier.
so now my question.
Let's say I have the following Code:
public class Main {
public static void main(String[] args) {
int variable1=2, variable2=2;
input(variable1, variable2);
System.out.println(variable1 + " " + variable2);
// this should output "1 3" on the console
}
private static void input(int variable1, int variable2) {
System.out.println(variable1 + " " + variable2);
// this will output "2 2" on the console
variable1 = 1;
variable2 = 3;
}
}
So the function input()
takes the Variables from main and outputs them (correctly).
But how can I transfer the changed Variables back to the main function?