Hint:
Use Addition and Subtraction Operators.
Explanation :
If n=4,m=5 then output will be n=5,m=4.
Code:
public class Swap
{
public static void main(String args[])
public static void main(String args[])
{
int x = 10;
int y = 20;
x = x+y;
y = x-y;
x = x-y;
System.out.println("After swap:");
System.out.println("x value: "+x);
System.out.println("y value: "+y);
}
}
int x = 10;
int y = 20;
x = x+y;
y = x-y;
x = x-y;
System.out.println("After swap:");
System.out.println("x value: "+x);
System.out.println("y value: "+y);
}
}
No comments:
Post a Comment