Monday, April 30, 2018

Swap two variables using third variable !

  1. public class SwapTwoNumberWithThirdVariable {
  2. public static void main(String[] args) {
  3. int a = 10;
  4. int b = 20;

  5. int temp;
  6. temp = a;
  7. a = b;
  8. b = temp;
  9. System.out.println("after swap value of a: " + a);
  10. System.out.println("after swap value of b: " + b);
  11. }
  12. }
Output: 
after swap value of a: 20
after swap value of b: 10

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...