tag:blogger.com,1999:blog-2964959029992147971.post3606597114784921929..comments2024-02-12T20:14:00.868+05:30Comments on InstanceOfJava: Swap two numbers without using third variablesaideshhttp://www.blogger.com/profile/03671387577197113199noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-2964959029992147971.post-48356552289617125732017-04-13T21:59:21.952+05:302017-04-13T21:59:21.952+05:30you Still trying ??you Still trying ??Kunal Tiwarihttps://www.blogger.com/profile/10054390382629758322noreply@blogger.comtag:blogger.com,1999:blog-2964959029992147971.post-17545591292838385392016-01-13T14:40:14.396+05:302016-01-13T14:40:14.396+05:30The first method is working fine with large values...The first method is working fine with large values. <br />I have tested with Integer.MAX_VALUE-20 and Integer.MAX_VALUE using JRE 1.8.0<br /><br />Calculation : <br />x = x + y<br /> = 2147483627 + 2147483647<br /> = -22<br /><br />y = x - y<br /> = -22 - 2147483647<br /> = 2147483627 (don't know how JVM calculated this)<br /><br />x = x - y<br /> = -22 - 2147483627<br /> = 2147483647 (don't know how JVM calculated this)<br /><br />I am trying to figure out how JVM calculates it. If someone knows the calculation logic. Please explain.<br />Anonymoushttps://www.blogger.com/profile/01876798850216837710noreply@blogger.comtag:blogger.com,1999:blog-2964959029992147971.post-76744977111525178982015-12-19T18:07:23.727+05:302015-12-19T18:07:23.727+05:301) and 2) doesn't work for all valid integers....1) and 2) doesn't work for all valid integers. <br />Take for 1) the following numbers: 1 and Integer.MAX_VALUE<br />Take for 2) the following numbers: any integer and 0<br />3) Could workDieterhttps://www.blogger.com/profile/07879473547366012655noreply@blogger.com