-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfraction.java
More file actions
39 lines (32 loc) · 1.09 KB
/
fraction.java
File metadata and controls
39 lines (32 loc) · 1.09 KB
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
35
36
37
38
39
import java.util.Scanner;
public class fraction{
public static void main(){
Scanner in = new Scanner(System.in);
System.out.println("Enter First Fraction");
int a = in.nextInt();// 1
System.out.println("-");
int b = in.nextInt();// 2
System.out.println("Enter Second Fraction");
int c = in.nextInt();// 3
System.out.println("-");
int d = in.nextInt();// 4
int x,y;
y = b*d;// 4*2 = 8
if (y%b != 0 || y%d != 0) System.out.println("Err");
x = (a*(y/b)) + (c*(y/d));// 1*(8/2) + 3*(8/4) => 4 + 6
System.out.println("Sum:\n" + x + "\n----\n" + y);
int nums[] = {2,3,5,7,9};
int m;
for (int j = 0; j <3 ; j++){
for (int i = 0; i < nums.length;i++){
if (x % nums[i] == 0 && y % nums[i] == 0){
x = x/nums[i];
y = y/nums[i];
}else{
continue;
}
}
}
System.out.println("==> \n" + x + "\n----\n" + y);
}
}