Skip to content

Commit 62ef1b5

Browse files
committed
Division
1 parent 3aeba10 commit 62ef1b5

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/medium/Division.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package medium;
2+
3+
/**
4+
* Have the function Division(num1,num2) take both parameters being passed
5+
* and return the Greatest Common Factor.
6+
* That is, return the greatest number that evenly goes into both numbers
7+
* with no remainder.
8+
* ---
9+
* For example: 12 and 16 both are divisible by 1, 2, and 4 so the output should be 4.
10+
* The range for both parameters will be from 1 to 10^3.
11+
*/
12+
public class Division {
13+
14+
/**
15+
* Division function.
16+
*
17+
* @param num1 input number 1
18+
* @param num2 input number 2
19+
* @return the GCF
20+
*/
21+
private static int division(int num1, int num2) {
22+
if (num1 == 0 || num2 == 0) {
23+
return num1 + num2;
24+
}
25+
26+
return division(num2, num1 % num2);
27+
}
28+
29+
/**
30+
* Entry point.
31+
*
32+
* @param args command line arguments
33+
*/
34+
public static void main(String[] args) {
35+
int result1 = division(20, 40);
36+
System.out.println(result1);
37+
int result2 = division(12, 16);
38+
System.out.println(result2);
39+
}
40+
41+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy