programming-examples/java/_Basics/How to swap two numbers without using temporary variable.java

16 lines
466 B
Java
Raw Normal View History

2019-11-15 12:59:38 +01:00
package com.scanftree.algos;
public class MySwapingTwoNumbers {
public static void main(String a[]) {
int x = 10;
int y = 20;
System.out.println("Before swap:");
System.out.println("x value: "+x);
System.out.println("y value: "+y);
x = x+y;
y=x-y;
x=x-y;
System.out.println("After swap:");
System.out.println("x value: "+x);
System.out.println("y value: "+y);
}
}