summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2022-11-07 18:22:42 +0200
committerIgor Pashev <pashev.igor@gmail.com>2022-11-07 18:22:42 +0200
commitac41f7286588e21b63563151206d0e10ce655ac8 (patch)
tree951e78d0f93e445b5d6889c9d943c0e2ed734ce4
parent53092ade72214d2ea75a8a38e10a317b41de7260 (diff)
downloadgcd-ac41f7286588e21b63563151206d0e10ce655ac8.tar.gz
Update Java
-rw-r--r--gcd.java53
1 files changed, 25 insertions, 28 deletions
diff --git a/gcd.java b/gcd.java
index 82722a1..8770beb 100644
--- a/gcd.java
+++ b/gcd.java
@@ -1,41 +1,38 @@
/*
* SYNOPSIS:
*
- * # gcj -o gcd --main=gcd gcd.java
- * # ./gcd 11 22 33 44 121
- *
* # javac gcd.java
* # java gcd 11 22 33
*
*/
-public class gcd
-{
- public static int gcd2(int a, int b) {
- int c;
- while (b != 0) {
- c = b;
- b = a % b;
- a = c;
- }
- return a;
+public class gcd {
+ public static long gcd2(long a, long b) {
+ long c;
+ while (b != 0) {
+ c = b;
+ b = a % b;
+ a = c;
}
+ return a;
+ }
- 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;
- }
+ public static long gcdn(long[] a) {
+ long r = a[0];
+ for (int i = 1; i < a.length; i++)
+ r = gcd2(r, a[i]);
+ return r;
+ }
+
+ public static void main(String[] argv) {
+ if (argv.length == 0)
+ return;
- public static void main(String [] argv) {
- if (argv.length == 0)
- return;
- 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));
+ long[] n = new long[argv.length];
+ for (int i = 0; i < argv.length; i++) {
+ n[i] = Long.parseLong(argv[i]);
}
-}
+ System.out.println(gcdn(n));
+ }
+}