Menu

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

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

System.out.println("Please enter two numbers");
Scanner sc= new Scanner(System.in);
int no1           = sc.nextInt();
int no2           = sc.nextInt();

System.out.println("BEFORE SWAPPING:first number = "+no1+" secondnumber = "+no2);
int temporary;
temporary =no2;
no2=no1;
no1=temporary;
System.out.println("AFTER SWAPPING:first number = "+no1+" second number = "+no2);


}}