About 2,680,000 results
Open links in new tab
  1. Java Program to Compute GCD - GeeksforGeeks

    Apr 4, 2025 · GCD (Greatest Common Divisor) of two given numbers A and B is the highest number that can divide both A and B completely, i.e., leaving the remainder 0 in each case. GCD is also called HCF(Highest Common Factor).

  2. Java Program to Find GCD of two Numbers

    In this program, you'll learn to find GCD of two numbers in Kotlin. This is done by using for and while loops with the help of if else statements.

  3. Java Program to Find GCD or HCF of Two Numbers

    Mar 28, 2021 · GCD (i.e. Greatest Common Divisor) or HCF (i.e. Highest Common Factor) is the largest number that can divide both the given numbers. Example: HCF of 10 and 20 is 10, and HCF of 9 and 21 is 3.

  4. Java Program to Find GCD of Two Numbers - Tpoint Tech

    In the following program, we have defined a recursive function named findGCD (). It parses two parameters a and b of type int. If the second number (b) is equal to 0, the method returns a as GCD, else returns a%b. Let's see another logic to find the GCD of two numbers.

  5. Java Program to Find GCD and LCM of Two Numbers Using …

    Dec 4, 2020 · In this approach, we perform the gcd operation on A and B repeatedly by replacing A with B and B with the modulo of A and B until the modulo becomes 0. Below is the implementation of to find GCD and LCM of Two Numbers Using Euclid’s Algorithm:

  6. Java: get greatest common divisor - Stack Overflow

    Oct 24, 2010 · GCD should a class with a bunch of overloaded static methods that takes in two numbers and gives it's gcd. And it should be part of the java.math package. As far as I know, there isn't any built-in method for primitives. But something as simple as this should do the trick: if (b==0) return a; return gcd(b,a%b);

  7. How to write a simple Java program that finds the greatest …

    The greatest common divisor (GCD) of two integers a and b is the largest integer that is a factor of both a and b. The GCD of any number and 1 is 1, and the GCD of any number and 0 is that number. One efficient way to compute the GCD of two numbers is to use Euclid's algorithm, which states the following:

  8. GCD of Two Numbers in Java | Methods to Find Greatest Common Divisor

    Explore different ways to compute the GCD of two numbers in Java using loops, recursion, custom methods, and the Euclidean algorithm with detailed examples.

  9. How to Find the GCD of Two Numbers in Java: A Comprehensive …

    Define a function findGCD (a, b) to compute the GCD of two numbers using the Euclidean algorithm: While b is not 0: 3. Define a function findGCDofArray (arr) to compute the GCD of an array of numbers: Set result = arr [0] (initialize with the first number in the array).

  10. Java Program to Calculate GCD of two numbers - Studytonight

    Apr 16, 2021 · In this program, we will see how to calculate the GCD of two numbers in java by using for loop. Create an instance of the Scanner class. Declare two variables. Ask the user to initialize these variables. Declare a variable to store the HCF and initialize it to 0. Use a for loop to calculate the GCD.