File tree 1 file changed +33
-0
lines changed
chapters/fundamental_algorithms/euclidean_algorithm
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -354,3 +354,36 @@ let chk2 = euclid_sub (128 * 12) (128 * 77)
354
354
let () = print_string ((int_of_string chk1) ^ "\n")
355
355
let () = print_string ((int_of_string chk2) ^ "\n")
356
356
```
357
+
358
+ ### Java
359
+ ``` java
360
+ // sumbitted by lolatomroflsinnlos
361
+ public static void main(String [] args) {
362
+
363
+ System . out. println(euclidSub(64 * 67 , 64 * 81 ));
364
+ System . out. println(euclidMod(128 * 12 , 128 * 77 ));
365
+
366
+ }
367
+
368
+ public static int euclidSub(int a, int b) {
369
+ while (a != b) {
370
+ if (a > b) {
371
+ a -= b;
372
+ } else {
373
+ b -= a;
374
+ }
375
+ }
376
+
377
+ return a;
378
+ }
379
+
380
+ public static int euclidMod(int a, int b) {
381
+ while (b != 0 ){
382
+ int temp = b;
383
+ b = a % b;
384
+ a = temp;
385
+ }
386
+
387
+ return a;
388
+ }
389
+ ```
You can’t perform that action at this time.
0 commit comments