Skip to content

Modified and cleaned last Java example for Euclidean Algo #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions chapters/euclidean_algorithm/code/java/EuclideanAlgo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// submitted by lolatomroflsinnlos, modified by xam4lor
public class EuclideanAlgo {
public static int euclidSub(int a, int b) {
a = Math.abs(a);
b = Math.abs(b);

while (a != b) {
if (a > b) {
a -= b;
} else {
b -= a;
}
}

return a;
}

public static int euclidMod(int a, int b) {
while (b != 0) {
int tmp = b;
b = a % b;
a = tmp;
}

return a;
}
}
8 changes: 8 additions & 0 deletions chapters/euclidean_algorithm/code/java/MainClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//submitted by lolatomroflsinnlos, modified by xam4lor
public class MainClass {
public static void main(String[] args) {
System.out.println("Euclidean Algorithm :");
System.out.println(EuclideanAlgo.euclidMod(64 * 67, 64 * 81));
System.out.println(EuclideanAlgo.euclidSub(128 * 12, 128 * 77) + "\n");
}
}
36 changes: 0 additions & 36 deletions chapters/euclidean_algorithm/code/java/euclidean_example.java

This file was deleted.

18 changes: 10 additions & 8 deletions chapters/euclidean_algorithm/euclidean.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
[import:2-8, lang="clojure"](code/clojure/euclidean_example.clj)
{% sample lang="cpp" %}
[import:20-33, lang="c_cpp"](code/c++/euclidean.cpp)
{% sample lang="java" %}
[import:3-16, lang="java"](code/java/EuclideanAlgo.java)
{% sample lang="js" %}
[import:15-29, lang="javascript"](code/javascript/euclidean_example.js)
{% sample lang="py" %}
Expand All @@ -23,8 +25,6 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
[import:3-15, lang="rust"](code/rust/euclidean_example.rs)
{% sample lang="ml" %}
[import:9-17, lang="ocaml"](code/ocaml/euclidean_example.ml)
{% sample lang="java" %}
[import:9-22, lang="java"](code/java/euclidean_example.java)
{% sample lang="go" %}
[import:25-38, lang="go"](code/go/euclidean.go)
{% endmethod %}
Expand All @@ -46,6 +46,8 @@ Modern implementations, though, often use the modulus operator (%) like so
[import:9-13, lang="clojure"](code/clojure/euclidean_example.clj)
{% sample lang="cpp" %}
[import:7-17, lang="c_cpp"](code/c++/euclidean.cpp)
{% sample lang="java" %}
[import:18-26, lang="java"](code/java/EuclideanAlgo.java)
{% sample lang="js" %}
[import:1-13, lang="javascript"](code/javascript/euclidean_example.js)
{% sample lang="py" %}
Expand All @@ -56,8 +58,6 @@ Modern implementations, though, often use the modulus operator (%) like so
[import:17-27, lang="rust"](code/rust/euclidean_example.rs)
{% sample lang="ml" %}
[import:3-7, lang="ocaml"](code/ocaml/euclidean_example.ml)
{% sample lang="java" %}
[import:24-35, lang="java"](code/java/euclidean_example.java)
{% sample lang="go" %}
[import:14-23, lang="go"](code/go/euclidean.go)
{% endmethod %}
Expand Down Expand Up @@ -88,6 +88,12 @@ Program.cs
{% sample lang="cpp" %}
### Cpp
[import, lang="c_cpp"](code/c++/euclidean.cpp)
{% sample lang="java" %}
### Java
EuclideanAlgo.java
[import, lang="java"](code/java/EuclideanAlgo.java)
MainClass.java
[import, lang="java"](code/java/MainClass.java)
{% sample lang="js" %}
### JavaScript
[import, lang="javascript"](code/javascript/euclidean_example.js)
Expand All @@ -103,10 +109,6 @@ Program.cs
{% sample lang="ml" %}
### Ocaml
[import, lang="ocaml"](code/ocaml/euclidean_example.ml)
{% sample lang="java" %}
### Java
[import, lang="java"](code/java/euclidean_example.java)
{% sample lang="go" %}
### Go
[import, lang="go"](code/go/euclidean.go)
{% endmethod %}
Expand Down