About 718,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). There are various approaches to finding the GCD of two given numbers. Approaches:

  2. Java Program to Find GCD of two Numbers

    The HCF or GCD of two integers is the largest integer that can exactly divide both numbers (without a remainder). Example 1: Find GCD of two numbers using for loop and if statement

  3. 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:

  4. 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.

  5. Finding Greatest Common Divisor in Java - Baeldung

    Feb 14, 2025 · In this tutorial, we’ll look at three approaches to find the Greatest Common Divisor (GCD) of two integers. Further, we’ll look at their implementation in Java. 2. Brute Force. For our first approach, we iterate from 1 to the smallest number given and check whether the given integers are divisible by the index.

  6. How to Find Greatest Common Divisor of two numbers in Java

    Here is my complete code example of how to find the GCD of two numbers in Java. This Java program uses Euclid's method to find the GCD of two numbers. They must be an integer, so make sure you check the numbers entered by the user like floating-point numbers are not allowed.

  7. Java Code Example: Greatest Common Divisor (GCD)

    Methods in Java Java Code Example: Greatest Common Divisor (GCD) The Greatest Common Divisor (GCD) of two numbers is the largest number that divides both numbers without leaving a remainder. For example, the GCD of 48 and 18 is 6 because …

  8. 4 Methods To Find GCD Of Two Numbers In Java (+Code Examples

    In this article, we will cover different methods to find the GCD of two numbers in Java, including loops, recursion, the Euclidean algorithm, and Java's built-in gcd () method, with practical examples and analysis. The Greatest Common Divisor (GCD) of two numbers is a crucial concept in mathematics and computer science.

  9. gcd in java Code Example

    public class GCD { public static void main (String [] args) { int n1 = 81, n2 = 153, gcd = 1; for (int i = 1; i <= n1...

  10. Java Program to Find GCD of Two Numbers - Source Code Examples

    In this tutorial, we will write a Java program to find out the GCD of two numbers. The GCD (Greatest Common Divisor) of two numbers is the largest positive integer number that divides both the numbers without leaving any remainder.

Refresh