Write a Java Program to Find G.C.D Using Recursion

Java Program to Find G.C.D Using Recursion

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Java Program to Find G.C.D Using Recursion
Java Program to Find G.C.D Using Recursion

Write a Java Program to Find G.C.D Using Recursion

PROGRAM: Java Program to Find G.C.D Using Recursion

/*Java Program to Find G.C.D Using Recursion*/

public class GCD {

public static void main(String[] args) {
int n1 = 366, n2 = 60;
int hcf = hcf(n1, n2);

System.out.printf(“G.C.D of %d and %d is %d.”, n1, n2, hcf);
}

public static int hcf(int n1, int n2)
{
if (n2 != 0)
return hcf(n2, n1 % n2);
else
return n1;
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *