swapping using XOR operator
import java.util.*;
public class swapusingxor {
public static void swap(int a, int b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
System.out.println("After swapping value of:" + a);
System.out.println("After swapping value of b:" + b);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a:");
int a = sc.nextInt();
System.out.println("Enter b:");
int b = sc.nextInt();
swap(a, b);
}
}
Comments
Post a Comment