Program to input two variables and swap them using third variable JAVA


Write a Program to input two variables and swap them using third variable.




import java.util.*;
class Swap2
{
  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int t;
    System.out.println("Before Swapping: " + " " +"a ="  + a + " b = " + b);
    t=a;
    a=b;
    b=t;
    System.out.println("a = " + a + ", b = " + b);
  }
}


     
                     

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com