Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/purvgwtw/public_html/tutorials/common.php on line 7
Java swapping of numbers without using third variable.
Sponsered Links
Categories
Sponsered Links

Java swapping of numbers without using third variable.

You all are aware of the word swapping. It is the interchanging of values. Here we are going to swap the two variables without using third variable.

class Swapping {
    public static void main(String[] args) {
        int num1 = 10;
        int num2 = 20;
        num1 = num1 + num2;
        num2 = num1 - num2;
        num1 = num1 - num2;
        System.out.println("After swapping, num1= " + num1 + " and num2= "+ num2);
    }
}

Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2014 PURVACOMPUTERS.COM All Right Reserved