展开全部
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();
}
}
class Fraction{
int a,b,c,d,e,f;
double score;
Fraction(int a ,int b)
{
this.a=a;
this.b=b;
}
double todouble()
{
return score = a/b;
}
Fraction plus(Fraction r)
{
a=a*r.b+r.a*b;
b=b*r.b;
return r;
}
Fraction multiply(Fraction r)
{
a=a*r.a;
b=b*r.b;
return r;
}
void print()
{
if(b==a)
System.out.println("1");
else
System.out.println(a/gcd(a, b)+"/"+b/gcd(a, b));
}
int gcd(int a,int b)
{
int m,n;
m=a;
n=b;
while(true)
{
if((m = m%n)==0)
return n;
if((n = n%m)==0)
return m;
}
}
}