java - is it possible to change the original variable when it is passed as an argument to the function -
this question has answer here:
- how pass primitive data type reference? 8 answers
am trying change value of variable when passed argument function, original value remains same, possible change?(i,e in below code want value of x 11)
public class runy { public static void main(string [] args) { int x=10; int y=change(x); system.out.println(x); system.out.println(y); } public static int change(int a) { a+=1; return a; }
}
i,e in below code want value of x 11)
with current code, won't possible if want change value of x
, don't need y
, can
int x=10; x=change(x); // store return value of change 'x'
Comments
Post a Comment