The example codes is below:
class ChangeVal
The example codes is below:
class ChangeVal
{
public static void main(String[] args)
{
int x=3;
int y=5;
//this method is common in using,easy to read
System.out.println("x="+x+",y="+y);
int temp;
temp=x;
x=y;
y=temp;
System.out.println("x="+x+",y="+y);
//method two
System.out.println("x="+x+",y="+y);
x=x+y;
y=x-y;//
x=x-y;
System.out.println("x="+x+",y="+y);
//this method is less in using ,beacuse it's difficult for reading,and contains a bit of skill
System.out.println("x="+x+",y="+y);
x=x^y;
y=x^y;//y=(x^y)^y=x
x=x^y;//x=x^(x^y)=y;
System.out.println("x="+x+",y="+y);
}
}