Java program for swapping of 2 numbers

Java program for swapping of 2 numbers using memory location

Java program for swapping of 2 numbers using temp

Program:-

import java.util.Scanner;

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

int num1,num2,temp;

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

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

}

Output:-

Enter num1:
5
Enter num2:
6
num1: 6 num2: 5

Try other language:-



Leave reply

Add your comments here

Back to Top