GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-Sep-2016, 23:42
arshi1586's Avatar
arshi1586 arshi1586 is offline
Account Disabled
 
Join Date: Sep 2016
Location: Bhopal , Madhya pradesh
Posts: 11
arshi1586 has a little shameless behaviour in the past

How to Swap two numbers without using third variable in Java?


How to Swap two numbers without using third variable in Java?
  #2  
Old 02-Sep-2017, 00:45
priya465 priya465 is offline
Account Disabled
 
Join Date: Aug 2017
Posts: 16
priya465 is an unknown quantity at this point

Re: How to Swap two numbers without using third variable in Java?


JAVA Code:
public class SwapElements {
 
        public static void main(String[] args) {
               
                int num1 = 10;
                int num2 = 20;
               
                System.out.println("Before Swapping");
                System.out.println("Value of num1 is :" + num1);
                System.out.println("Value of num2 is :" +num2);
               
                //add both the numbers and assign it to first
                num1 = num1 + num2;
                num2 = num1 - num2;
                num1 = num1 - num2;
               
                System.out.println("Before Swapping");
                System.out.println("Value of num1 is :" + num1);
                System.out.println("Value of num2 is :" +num2);
        }
 
 
}
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
JAVA Online Training with real time scenarios INDIA | USA | UK | CANADA johnwatson Computer Programming Advertisements & Offers 0 15-Sep-2014 00:59
Exception in thread "main" java.lang.NullPointerException at Cameras.sortByName(Came Dan0756 Java Forum 1 24-Aug-2012 19:35
C++ sorting out numbers Gondar0512 C++ Forum 5 18-Jan-2012 18:02
How to flip an image horizontally? kkmoslehpour C Programming Language 2 13-Nov-2011 10:17
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 15:13

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:06.


vBulletin, Copyright © 2000 - 2017, Jelsoft Enterprises Ltd.