File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments