-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP120808.java
More file actions
26 lines (22 loc) · 791 Bytes
/
Copy pathP120808.java
File metadata and controls
26 lines (22 loc) · 791 Bytes
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
package intro;
public class P120808 {
public static void main(String[] args) {
int[] result = solution(1, 2,3,4);
System.out.println(result[0] + "..." + result[1]);
}
public static int[] solution(int numer1, int denom1, int numer2, int denom2) {
int[] answer = new int[2];
answer[0] = (numer1 * denom2) + (numer2 * denom1);
answer[1] = denom1 * denom2;
return getInts(answer);
}
public static int[] getInts(int[] answer) {
int gdcNum = gdc(Math.max(answer[0], answer[1]), Math.min(answer[0], answer[1]));
answer[0] = answer[0] / gdcNum;
answer[1] = answer[1] / gdcNum;
return answer;
}
public static int gdc(int a, int b){
return a % b == 0 ? b : gdc(b, a % b);
}
}