Java Program Swap 2 Numbers Without Third Variable

      No Comments on Java Program Swap 2 Numbers Without Third Variable
class scan
{
public static void main(String arg[])
 {
   int a=5;
   int b=10;
 System.out.println("Value of a before swaping:- "+a);
 System.out.println("Value of b before swaping:- "+b);
a=a+b;
b=a-b;
a=a-b;
System.out.println("Value of a after Swaping:- "+a);
System.out.println("Value of b after Swaping:- "+b);
}
}

OUTPUT

Value of a before swaping:- 5
Value of b before swaping:- 10
Value of a after Swaping:- 10
Value of b after Swaping:- 5

Leave a Reply

Your email address will not be published. Required fields are marked *