In the previous blog we saw  how to find the ASCII value of the character .Now, we will see how to swap two numbers using a variable.

Basic Data Type:- int, char, float, double

int Datatype:-Its an integer datatype .Its of 2 bytes .Its range is âˆ’32,768 to 32,767.

char Datatype:-Its an character datatype. Its of  1 byte. Its range is -128 to 127 .

float Datatype:-Its for floating point numbers. Its of  4 byte.

double Datatype :-Its for large floating point numbers .Its of 8 byte

To swap two numbers using a variable :-

import java.io.*;

import java.util.*;

public class swap{

    public static void main (String [] args)

    {

        int number1,number2,temp;

        System.out.println("Enter two numbers:");

        Scanner sc =new Scanner(System.in);

        number1=sc.nextInt();

        number2=sc.nextInt();

        System.out.println("Before swapping "+number1+" "+number2);

       temp=number1;

       number1=number2;

       number2=temp;

        System.out.print("After swapping "+number1+" "+number2);

    }

}

Algorithm:-
1.Start 
2.Declare 3 variables of type int as number1,number2,temp
3.Use a print statement to display enter two numbers 
4.Use a scanner class to get the input of the numbers 
5.Use a print statement to display before swapping 
5.Store the number1 variable in a temp variable .
6.Now,store the number2 value in number1 variable 
7.Now store the value of temp variable (i.e., which has the number1 variable before swapping in number2 variable .
8.Finally print the number1 and number2 variable by display a text "After swapping" .
9.Stop 
 
Screenshot:-
1.Program Screenshot:-



2.Code Screenshot:-



In the next blog we will see whether two numbers are equal .