Swap two integers without using temp/third variable - Java Interview Questions -8

  Рет қаралды 43,276

Naveen AutomationLabs

Naveen AutomationLabs

Күн бұрын

Пікірлер: 15
@srknanduri
@srknanduri 3 жыл бұрын
x = (x + y) - ( y = x ); Hi Naveen, this also would be an optimal solution in a single line
@navathutejomai1038
@navathutejomai1038 2 жыл бұрын
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.
@keshavjha2099
@keshavjha2099 5 ай бұрын
public static void swap(int x, int y){ x=x+y; y=x-y; x=x-y; } hope this helps
@programminghubbharat7535
@programminghubbharat7535 3 жыл бұрын
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
@tripathiakul
@tripathiakul 7 жыл бұрын
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.
@tarikgulsever5191
@tarikgulsever5191 5 жыл бұрын
Hi Naveen can make video to find second largest number in the array
@sauravhateme
@sauravhateme 4 жыл бұрын
There is one more logic i tried after watching it: x=(x+y) - (y=x);
@barshabhattacharjee6788
@barshabhattacharjee6788 4 жыл бұрын
For more visit: kzbin.info/www/bejne/fpClm2uBj86pbKs
@bharatvarshney2666
@bharatvarshney2666 6 жыл бұрын
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
@naveenautomationlabs
@naveenautomationlabs 6 жыл бұрын
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)
@bharatvarshney2666
@bharatvarshney2666 6 жыл бұрын
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.
@acGameplayStudios
@acGameplayStudios 6 жыл бұрын
See the execution has been done and the results have been printed in the console, and i have also tested and tried it.
@bharathkoneru4008
@bharathkoneru4008 5 жыл бұрын
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
@achintyasett9621
@achintyasett9621 4 жыл бұрын
@@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
Swap two Strings without using temp/third variable - Java Interview Questions -9
10:46
Interview Question : Compare Two Integer Numbers (Integer Caching) in #Java
3:56
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН
Largest & Smallest Numbers In Array - Java Interview Questions - 6
13:41
Naveen AutomationLabs
Рет қаралды 97 М.
How to Find Duplicates Elements in Java Array? - Java Interview Questions -5
29:34
How to Reverse a String - Java Interview Question -1
11:29
Naveen AutomationLabs
Рет қаралды 303 М.
Find Duplicate Elements in An Array || Important Java Interview Questions
22:36
Naveen AutomationLabs
Рет қаралды 53 М.
How to Reverse an Integer - Java Interview Question -3
11:35
Naveen AutomationLabs
Рет қаралды 111 М.
DeepSeek R1 Just Revolutionized AI Forever
21:06
Cole Medin
Рет қаралды 23 М.
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН