Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Java program to swap two numbers using bitwise xor operator

import java.util.Scanner;public class Main {public static void main(String args[]){int m, n;Scanner s = new Scanner(System.in);System.out.print("Enter the first number");m = s.nextInt();System.out.print("Enter the second number");n = s.nextInt();m = m ^ n;n = m ^ n;m = m ^ n;System.out.println("After Swapping the number");System.out.println("First number:"+m);System.out.println("Second number:"+n);}}
Source by inlarn.com #
 
PREVIOUS NEXT
Tagged: #Java #program #swap #numbers #bitwise #xor #operator
ADD COMMENT
Topic
Name
3+4 =