- Trending Categories
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
- Related Articles
- Java Program to Swap Two Numbers.
- C++ Program to Swap Two Numbers
- Haskell Program to Swap Two Numbers
- Kotlin Program to Swap Two Numbers
- Find XOR of two number without using XOR operator in C++
- Java program to swap two integers
- 8085 program to swap two 8-bit numbers
- How to Swap Two Numbers in Swift Program?
- 8085 program to swap two 8 bit numbers using Direct addressing mode
- 8085 program to swap two 16-bit numbers using Direct addressing mode
- Write a Golang program to swap two numbers without using a third variable
- C Program to find sum of two numbers without using any operator
- Importance of XOR operator in Java?
- Add two numbers using ++ operator in C++.
- Swap two numbers in C#

Advertisements