Sunday 8 June 2014

Program to swap the values of two variables a and b without using any third variable

// this program swaps the values of two variables a and b without using any third variable

public class swap
{
public static void main(String[] args)
{
int a,b;
a=5;
b=3;

a=a+b;
b=a-b;
a=a-b;
System.out.print("a = "+a);
System.out.println("b = "+b);

}

}

output:
a=3
b=5

No comments:

Post a Comment

SAY HELLO!!