Hey I really got confuse with the return in java.Please help me to solve my misery...Thanks in advance:)
public static void main(String[] args){
System.out.println(addThem(1,2));
}
public static int addThem(int a, int b){
int c = a + b;
return c;
}
I can understand that in the code above return "c" as a new variable/result of addition. Here is another method that make me confuse>>
public static void main(String[] args){
int d = 5;
tryToChange(d);
System.out.println("tryToChange d = " + d);
}
public static void tryToChange (int d){
d = d + 1;
System.out.println("tryToChange d = " + d);
}
when I try to execute this code it return
tryToChange d = 6
tryToChange d = 5
it shows that the value in method "tryToChange" is returning the value of 5+1, It also returns value.but why is it void?