swapping of two numbers in java
previous Nextswapping of two numbers in java
class Swap_number{
public static void main(String[] args) {
int a = 10;
int b = 20;
int temp;
temp = a;
a = b;
b = temp;
System.out.println(a);
System.out.println(b);
}
}
Output :
20 10
swapping of two numbers without using third variable in java
class SwapNumber{
public static void main(String[] args) {
int a = 10;
int b = 20;
a = a + b;
b = a - b;
a = a - b;
System.out.println(a);
System.out.println(b);
}
}
Output :
20 10
