How to swap variables values?
Swapping is to change values of each other. e.g I have two variables int a = 5; int b = 7; I want to swap both values like a = 7l and b = 5 1. Using third variable - We can swap values taking third variable. e.g int a = 5.; int b = 7; int temp; //Assign value to temp variable temp = a; //Change the value of a to b a = b; //Last set value of b b = temp; So now output is a = 7 and b = 5 2. Using addition and Subtraction method - int a = 5; int b = 7; //Make addition of both numbers a = a + b; //To find out value of b b = a - b; //To find the value of a by new b value a = a - b; 3. Using Multiplication and Division method - int a = 5; int b = 7; //Make addition of both numbers a = a * b; //To find out value of b b = a / b; //To find the value of a by new b value a = a / b; |
This blog helping people to learn about some basic programming tips that I have experience in my career. I am writing programming tips about Javascript, JSON, jQuery, PHP, Symfony, Java and Object oriented Programming.
Thursday, October 11, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment