![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to swap two numbers using XOR operator
Following is a program to swap two numbers using XOR operator.
Example
public class ab31_SwapTwoNumberUsingXOR { public static void main(String args[]){ int a,b; Scanner sc = new Scanner(System.in); System.out.println("Enter a value :"); a = sc.nextInt(); System.out.println("Enter b value :"); b = sc.nextInt(); a = a^b; b = a^b; a = a^b; System.out.println("Value of the variable a after swapping : "+a); System.out.println("Value of the variable b after swapping : "+b); } }
Output
Enter a value : 55 Enter b value : 64 Value of the variable a after swapping : 64 Value of the variable b after swapping : 55
Advertisements