write a program in Java to interchange the value of two nos. without using 3rd variable.
Answers
Answered by
4
public class Interchange
{
public static void main(String args[])
{
int X = 5; //X = 5
int Y = 7; //Y = 7
int X = X + Y; //X = 12
int Y = X - Y; //Y = 5
int X = X - Y; //X = 7
}
}
And voila we have exchanged the values of two numbers without using a third variable.
{
public static void main(String args[])
{
int X = 5; //X = 5
int Y = 7; //Y = 7
int X = X + Y; //X = 12
int Y = X - Y; //Y = 5
int X = X - Y; //X = 7
}
}
And voila we have exchanged the values of two numbers without using a third variable.
Saquiba1:
thanks a lot
Similar questions