Java Program:

- To swap 2 numbers

Example:

User Input
1st number: 3
2nd number: 5

After Swap, Output:
1st number : 5
2nd number : 3

import java.util.Scanner;
public class SwapProgram {
  public static void main(String []args) {
    int n1,n2,temp;
    Scanner userInput = new Scanner(System.in);
    System.out.print("Enter 1st number : ");
    n1 = userInput.nextInt();
    System.out.print("Enter 2nd number : ");
    n2 = userInput.nextInt();

    temp=n1;
    n1=n2;
    n2=temp;
    System.out.println("After Swap\n 1st number :"+ n1 
    + "\n 2nd number : " + n2);
  }
}

Output:

  Enter 1st number : 7
  Enter 2nd number : 15
  After Swap
  1st number : 15
  2nd number : 7
Program
basic

Here we are using 3rd variable (above code temp)

temp = n1;  //Insert 1st variable data into temp variable
n1 = n2;  //Insert 2st variable data into 1st variable
n2 = temp;  //Finally, Insert temp variable data into 2nd variable
Concept

Coming Soon !

Quick
Tutorial

Quote

A good decision is based on knowledge and not on numbers.