Output:
Click Here For Java Online Compiler
Solution:
*** Swap Two Numbers Without Using Third Variable *** *** Before swapping *** a = 123 b = 456 *** After swapping *** a = 456 b = 123
Click Here For Java Online Compiler
Solution:
public class SwapTwoNumbers2 { public static void main(String[] args) { int a = 123; int b = 456; System.out.println("*** Swap Two Numbers Without Using Third Variable ***" + "\n"); System.out.println("*** Before swapping ***"); System.out.println("a = " + a); System.out.println("b = " + b); a = a + b; b = a - b; a = a - b; System.out.println("*** After swapping ***"); System.out.println("a = " + a); System.out.println("b = " + b); } }
comment 2 comments:
more_vertgreat bro keep it up
29 January 2018 at 13:23Can we do the same using division operation?
10 January 2019 at 00:35Java Code Korner
sentiment_satisfied Emoticon