Menu

Swap two numbers without using temp variable or third variable- Java Program

import java.util.*;
class Swap_without_third_variable{
public static void main(String args[]){

System.out.println("Enter two numbers to swap");
Scanner sc= new Scanner(System.in);
int no1=sc.nextInt();
int no2=sc.nextInt();

System.out.println("The numbers before swapping are " +no1+" and "+no2);
no1=no1+no2;
no2=no1-no2;
no1=no1-no2;
System.out.println("The numbers after swapping are " +no1+" and "+no2);


}}