Java program for swapping of 2 number without temp

Java program for swapping of 2 number without temp memory allocation

Java program for swapping of 2 numbers


Program:-

import java.util.Scanner;

class group{
public static void main(String ang[]){
Scanner data= new Scanner(System.in);

int num1,num2;

System.out.println("Enter num1:");
num1=data.nextInt();
System.out.println("Enter num2:");
num2=data.nextInt();

num1=num1+num2;
num2=num1-num2;
num1=num1-num2;

System.out.println("num1: "+ num1 +" num2: "+ num2);
}
}

Output:-

Enter num1:
56
Enter num2:
89
num1: 89 num2: 56

Try other language:-

2 Comments

Add your comments here

Back to Top