diff options
-rw-r--r-- | gcd.java | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -1,28 +1,28 @@ public class gcd { - public static int gcd2(int a, int b) { - int c; + public static int gcd2(int a, int b) { + int c; while (b != 0) { c = b; b = a % b; a = c; } - return a; - } + return a; + } - public static int gcdn(int [] a) { - int r = a[0]; + public static int gcdn(int [] a) { + int r = a[0]; for (int i = 1; i < a.length; i++) r = gcd2(r, a[i]); - return r; - } + return r; + } - public static void main(String [] argv) { + public static void main(String [] argv) { int [] n = new int [argv.length]; for (int i = 0; i < argv.length; i++) { n[i] = Integer.parseInt(argv[i]); } System.out.println(gcdn(n)); - } + } } |