分数相乘相加
import java.util.Scanner;
class Fraction{
int a;
int b;
public Fraction () {
}
public Fraction (int a, int b) {
this .a = a;
this .b = b;
}
public double toDouble (){
double temp = a*1.0 /b;
return temp;
}
public void print (){
int temp = GCD(this .a, this .b);
this .a = this .a / temp;
this .b = this .b / temp;
if (a == b && a == 1 ){
System.out.println("1" );
}else {
System.out.println(a+"/" +b);
}
}
public Fraction multiply (Fraction r){
Fraction temp = new Fraction((this .a*r.a), (this .b*r.b));
return temp;
}
private int GCD (int a, int b){
int temp;
if (a < b){
temp = a;
a = b;
b = temp;
}
while (b!=0 ){
temp = b;
b = a%b;
a = temp;
}
return a;
}
public Fraction plus (Fraction r){
Fraction temp = new Fraction();
temp.b = this .b * r.b;
temp.b = temp.b/GCD(this .b, r.b);
temp.a = (this .a*(temp.b/this .b) + r.a*(temp.b/r.b));
return temp;
}
}
public class Main {
public static void main (String[] args) {
Scanner in = new Scanner(System.in);
Fraction a = new Fraction(in.nextInt(), in.nextInt());
Fraction b = new Fraction(in.nextInt(),in.nextInt());
a.print();
b.print();
a.plus(b).print();
a.multiply(b).plus(new Fraction(5 , 6 )).print();
a.print();
b.print();
in.close();
}
}