CJCoding With Joseph

Recursive Greatest Common Divisor

Write a recursive method gcd(int a, int b) that returns the greatest common divisor of a and b using Euclid's algorithm: when b is 0 the answer is a; otherwise the answer is gcd(b, a % b). Call it with 48 and 18 and print the result:

6

Use System.out.println.

Expected Output:

6
Topics:
Methods
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.