The intent of this page is to collection the best program and help programmers to find good blog posts to read. Some of these blogs may not be written by Java developers, but Java developers should find it useful or interesting. Reading those blogs should be fun and often bring some fresh ideas

Monday, August 3, 2020

Program Greatest common Divisor

Program to calculate the GCD of two number using recusion


import java.util.*;

public class GDC{
public static int gcd(int a, int b){
        if(b==0)
        return a;
        return  gcd(b,a%b);
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the n1: ");
int n1 = sc.nextInt();
System.out.println("Enter the n2");
int n2 = sc.nextInt();
        System.out.println(gcd(n1,n2));
}
}

No comments:

Post a Comment

If you have any doubt . Please let me know

String Operation

String Operation Using collection Framework Sorting Order  public static void sortAccending(String s) { char[] arr = s.toCharArray(); ...

Adbox