FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/Maths/GCDRecursion.java at master · coder2hacker/Java · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
coder2hacker
/
Java
Public
forked from
TheAlgorithms/Java
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
Maths
/
GCDRecursion.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (29 loc) · 709 Bytes
Breadcrumbs
Java
/
Maths
/
GCDRecursion.java
Copy path
File metadata and controls
34 lines (29 loc) · 709 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
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
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL