x = (x + y) - ( y = x ); Hi Naveen, this also would be an optimal solution in a single line
@navathutejomai10382 жыл бұрын
Sir I got a doubt as string is immutable how can we concatenate and assign to same string, just read on net that a new string is created and it reference is set to the object reference.
@keshavjha20995 ай бұрын
public static void swap(int x, int y){ x=x+y; y=x-y; x=x-y; } hope this helps
@programminghubbharat75353 жыл бұрын
hello Navin sir, i'm a EC student, In XOR Swapping, X^Y = 1111 (15) But Y = X^Y is 5 //Instead of 10 And X = X^Y is 10 // Instead of 5
@tripathiakul7 жыл бұрын
Is xor operator is valid for all the inputs . As per the Xor operator it depends upon on placing of 0&1. I have tested it for many inputs and its working but amazing . please let me know how can anybody thinks like that.
@tarikgulsever51915 жыл бұрын
Hi Naveen can make video to find second largest number in the array
@sauravhateme4 жыл бұрын
There is one more logic i tried after watching it: x=(x+y) - (y=x);
@barshabhattacharjee67884 жыл бұрын
For more visit: kzbin.info/www/bejne/fpClm2uBj86pbKs
@bharatvarshney26666 жыл бұрын
I think there is some mistake in multiplication without using third variable x = x * y; // x now becomes 50 y = x / y; // y becomes 10 // instead of 5 x = x / y; // x becomes 5 // instead of 10 you have use int x=5, y=10
@naveenautomationlabs6 жыл бұрын
No, your logic is wrong man! It is like this : x = x * y; // x now becomes 50 y = x / y; // y becomes 5 (y=>50/10=5) x = x / y; // x becomes 10 (x=>50/5=10)
@bharatvarshney26666 жыл бұрын
Sir, i could not commit wrong logic actually i have comparing with video or notes, in video you have mention x=5, y=10 or in notes it vice versa.
@acGameplayStudios6 жыл бұрын
See the execution has been done and the results have been printed in the console, and i have also tested and tried it.
@bharathkoneru40085 жыл бұрын
x=5, y=10; x = x*y; //5*10=50 y = x/y; //50/10=5 now y value has been changed to 5 x = x/y; // still x has value 50 and on performing right hand side division x/y i.e, 50/5=10 and assignment, the value of x is now changed to 10. Swapping achieved with * operator
@achintyasett96214 жыл бұрын
@@naveenautomationlabs Naveen swapping without using third variable by multiplication & division doesn't work if any one of the 2 number is ZERO. It throws ArithmeticException