Divide one BigInteger from another BigInteger in Java


Use the BigInteger divide() method in Java to divide one BigInteger from another.

First, let us create some objects.

BigInteger one, two, three;
one = new BigInteger("200");
two = new BigInteger("100");

Divide the above and assign it to the third object −

three = one.divide(two);

The following is an example −

Example

 Live Demo

import java.math.*;
public class BigIntegerDemo {
   public static void main(String[] args) {
      BigInteger one, two, three;
      one = new BigInteger("200");
      two = new BigInteger("100");
      // division
      three = one.divide(two);
      String res = one + " / " + two + " = " +three;
      System.out.println("Result: " +res);
   }
}

Output

Result: 200 / 100 = 2

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 29-Jun-2020

93 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements