Swapping using 3rd variable in JAVA - 👑 सार्थक मुंड S3 🤴🏻

Swapping using 3rd variable in JAVA

Write a program (WAP) in JAVA to read two numbers from keyboard(User Input) and exchanging the value of two variable(Swapping).

import java.util.Scanner;

class Sarthakmunds3

{
  public static void main(String args[])
  {
     int a, b, temp;
     System.out.println("Enter A and B :");
     Scanner in = new Scanner(System.in);
        
     a = in.nextInt();
     b = in.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);
    }

Try it Yourself ➠
Must Read :-
  1. Blogger Tutorial
  2. C Programs
  3. C++ Programs
  4. Java Programs
  5. Python Programs
  6. Programming Notes 
  7. Questions & Answers
  8. My Codes : HTML, CSS & JS
  9. All Subject Notes
Previous article
Next article

Leave Comments

Post a Comment

Articles Ads

Articles Ads 1

Articles Ads 2

Advertisement Ads