how to swap to variables without using thrid variable in java?

Answer Posted / igor polivanyi

It’s pretty simple:

int a = 12;
int b = 34;

a = a + b;
b = a - b;
a = a - b;

And for real cowboys, it could be simplified further:

a -= (b = (a += b) - b);

Is This Answer Correct ?    8 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is oop better than procedural?

697


What is polymorphism used for?

654


What is the oops and benefits of oops programming?

636


What is overloading and its types?

703


Why it is called runtime polymorphism?

677






What is class in oop with example?

702


assume the program must insert 4 elements from the key board and then do the following programs.sequential search(search one of the elements),using insertion sort(sort the element) and using selection sort(sort the element).

1767


Get me a number puzzle game-program

1780


What is encapsulation with real life example?

675


What is an example of genetic polymorphism?

751


What is difference between pop and oop?

700


What is polymorphism in oop example?

618


What is debug class?what is trace class? What differences are between them? With examples.

1710


Write a java applet that computes and displays the squares of values between 25 and 1 inclusive and displays them in a TextArea box

2130


They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?

1491