GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/Maths/GCDRecursion.java at master · qdu123/Java Expand file tree/ Copy pathGCDRecursion.javaMore file actions 36 lines (31 loc) · 800 Bytes / Copy pathGCDRecursion.javaFile metadata and controls36 lines (31 loc) · 800 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 package Maths; /** * @author https://github.com/shellhub/ */ public class GCDRecursion { public static void main(String[] args) { System.out.println(gcd(20, 15)); /* output: 5 */ System.out.println(gcd(10, 8)); /* output: 2 */ System.out.println(gcd(gcd(10, 5), gcd(5, 10))); /* output: 5 */ } /** * get greatest common divisor * * @param a the first number * @param b the second number * @return gcd */ public static int gcd(int a, int b) { if (a < 0 || b < 0) { throw new ArithmeticException(); } if (a == 0 || b == 0) { return Math.abs(a - b); } if (a % b == 0) { return b; } else { return gcd(b, a % b); } } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |