Division of two numbers in JAVA

Division of two numbers in JAVA

 In the previous blog we saw multiplication of two numbers. Now, we will see about datatypes and division of two numbers .

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

int Datatype:-Its an integer datatype .Its of 4 bytes .Its range is -2,147,483,648 to 2,147,483,647.

char Datatype:-Its an character datatype. Its of  2 bytes. 

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

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

1.Division of two numbers using int datatype 

import java.io.*;

import java.util.*;

public class division{

    public static void main (String [] args)

    {

        int number1,number2,number3;

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

        Scanner sc =new Scanner(System.in);

        number1=sc.nextInt();

        number2=sc.nextInt();

        number3=number1/number2;

        System.out.print("Quotient of two number is "+number3);

    }

}

Algorithm:-

1.Start 

2.Import the packages respectively.

3.Declare the variables number1 and number 2  by using the datatype int .Use the print statement and display a message "Enter two numbers:"

4.By using the scanner class get the input  by using System.in and create the object sc 

5.Get the first & second number by using scanner class .

6.By using number3 variable divide the two numbers number1 & number2 

7. The print statement gets displayed in the next line to  display a message "division  of two numbers" along with the division of two numbers .

8.Stop.

Screenshot:-

1.Code Screenshot:-


2.Output Screenshot:-


2.Division of two numbers using float datatype 

import java.io.*;

import java.util.*;

public class division{

    public static void main (String [] args)

    {

        float number1,number2,number3;

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

        Scanner sc =new Scanner(System.in);

        number1=sc.nextFloat();

        number2=sc.nextFloat();

        number3=number1/number2;

        System.out.print("Quotient of two number is "+number3);

    }

}

Algorithm:-

1.Start 

2.Import the packages respectively.

3.Declare the variables number1 and number 2  by using the datatype float .Use the print statement and display a message "Enter two numbers:"

4.By using the scanner class get the input  by using System.in and create the object sc .

5.Get the first & second number by using scanner class .

6.By using number3 variable divide the two numbers number1 & number2 

7. The print statement gets displayed in the next line to  display a message "Division of two numbers" along with the Division of two numbers .

8.Stop.

Screenshot:-

1.Code Screenshot:-


2.Output Screenshot:-


3.Division of two numbers using double datatype 

import java.io.*;
import java.util.*;
public class division{
    public static void main (String [] args)
    {
        double number1,number2,number3;
        System.out.println("Enter two numbers:");
        Scanner sc =new Scanner(System.in);
        number1=sc.nextDouble();
        number2=sc.nextDouble();
        number3=number1/number2;
        System.out.print("Quotient of two number is "+number3);
    }
}

Algorithm:-

1.Start 

2.Import the packages respectively.

3.Declare the variables number1 and number 2  by using the datatype double .Use the print statement and display a message "Enter two numbers:"

4.By using the scanner class get the input  by using System.in and create the object sc .

5.Get the first & second number by using scanner class .

6.By using number3 variable divide the two numbers number1 & number2 

7. The print statement gets displayed in the next line to  display a message "Division of two numbers" along with the division of two numbers .

8.Stop.

Screenshot:-

1.Code Screenshot:-


2.Output Screenshot:-


In the next blog we will see about  remainder of two numbers. 

0 Comments