Java BigInteger gcd() methodThe gcd() method of Java BigInteger class is used to get the greatest common divisor of absolute values of two BigInteger. This method returns a BigInteger whose value is the greatest common divisor of abs (this) and abs (val). Greatest Common Divisor:The greatest common divisor (gcd) of two or more integers which are not all zero, is the largest positive integer that divides each of the integers. For example, the gcd of 10 and 20 is 10 Syntax:Parameter:val - value with which the GCD is to be computed. Returns:This method returns GCD( abs(this) , abs(val) ) Exception:NA Note:Example 1Test it NowOutput: GCD of 12 and 10 is 2 Example 2Test it NowOutput: GCD of -12 and -10 is 2 Example 3Test it NowOutput: GCD of 12 and 0 is 12 Next TopicJava BigInteger |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India