Prime number in Java

Prime number in Java: Prime number is a number that is greater than 1 and divided by 1 or itself. In other words, prime numbers can’t be divided by other numbers than itself or 1. For example 2, 3, 5, 7, 11, 13, 17…. are the prime numbers.

Let’s see the prime number program in java.


Can you Access a method in a Inner Class

Computing the GCD

In this challenge, we learn how to compute GCD using the Euclidean algorithm.

Here’s a helpful video on the topic:


Given two integers, xx and yy, a recursive technique to find their GCD is the Euclidean Algorithm.

The algorithm states that, for computing the GCD of two positive integers xx and yy, if xx and yy are equal, GCD(x,y)=xGCD(x,y)=x. Otherwise GCD(x,y)=GCD(xy,y)GCD(x,y)=GCD(x−y,y) if x>yx>y. There are a few optimizations that can be made to the above logic to arrive at a more efficient implementation.