Sunday, February 12, 2017

Java program to swap two numbers without using temporary variable.

import static java.lang.System.out;
class Swap
{
static public void main(String args[])
{
int a=10,b=20;
out.println("Before Swap a = "+a+" b = "+b);
a=a+b;
b=a-b;
a=a-b;
out.println("After Swap a = "+a+" b = "+b);
    }
}

Share this

0 Comment to "Java program to swap two numbers without using temporary variable."

Post a Comment