Swap two number

import java.util.*;
import java.util.Scanner;
class Swap
{
public static void main(String args[])
{
int a,b,temp;
Scanner sc=new scanner(System.in);
System.out.print("Enter the value of a,b:");
a=sc.nextInt();
b=sc.nextInt();
System.out.println("Before swapping\na="+a+"\nb="+b);
temp=a;
a=b;
b=temp;
System.out.println("After Swapping\na="+a+"\nb="+b);
}
}
OUTPUT:
Enter the value of a,b: 
15
20
Before Swapping a=15 b=20
After Swapping a=20 b=15
Translate »