I'm trying to alter the variable value in java? The following code works, it changes x,y value from 0 to 100:
public void tricky(Point arg1)
{
arg1.x = 100;
arg1.y = 100;
}
public static void main(String [] args)
{
Point pnt1 = new Point(0,0);
System.out.println("X: " + pnt1.x + " Y: " +pnt1.y);
tricky(pnt1);
System.out.println("X: " + pnt1.x + " Y:" + pnt1.y);
}
But why the following code doesn't work?
public class Solution {
public static void tricky(int arg1)
{
arg1 = 100;
}
public static void main(String [] args)
{
int pnt1 = 0;
System.out.println(pnt1);
tricky(pnt1);
System.out.println(pnt1);
}
}