# 【蓝桥杯】_05有理数类

package java2013B;

/**
* @Author bennyrhys
* @Date 2020-03-11 22:07
*

class Rational
{
private long ra;
private long rb;

private long gcd(long a, long b){
if(b==0) return a;
return gcd(b,a%b);
}
public Rational(long a, long b){
ra = a;
rb = b;
long k = gcd(ra,rb);
if(k>1){ //需要约分
ra /= k;
rb /= k;
}
}
// 加法
return ________________________________________;  //填空位置
}
// 乘法
public Rational mul(Rational x){
return new Rational(ra*x.ra, rb*x.rb);
}
public String toString(){
if(rb==1) return "" + ra;
return ra + "/" + rb;
}
}

Rational a = new Rational(1,3);
Rational b = new Rational(1,6);
System.out.println(a + "+" + b + "=" + c);

*/
public class _05有理数类 {

public static void main(String[] args) {
Rational a = new Rational(1,3);
Rational b = new Rational(1,6);
System.out.println(a + "+" + b + "=" + c);
}

static class Rational
{
private long ra;
private long rb;

private long gcd(long a, long b){
if(b==0) return a;
return gcd(b,a%b);
}
public Rational(long a, long b){
ra = a;
rb = b;
long k = gcd(ra,rb);
if(k>1){ //需要约分
ra /= k;
rb /= k;
}
}
// 加法
return new Rational(this.ra * x.rb + this.rb * x.ra, this.rb * x.rb);  //填空位置
}
// 乘法
public Rational mul(Rational x){
return new Rational(ra*x.ra, rb*x.rb);
}
public String toString(){
if(rb==1) return "" + ra;
return ra + "/" + rb;
}
}
}

# 文末福利

1. 通过公众号提示的关键字可以领取竞赛资料。但是，有时候会失效，小伙伴可以在后台留言提醒我修复。
2. 最后一波分享一些很有意义的开源干货

SpringBoot两小时快速入门，极客表白浪漫红包程序
https://github.com/bennyrhys/LuckyMoney-SpringBootProject
SpringBoot两小时快速入门，基因芯片个人信息程序
https://github.com/bennyrhys/Girl-SpringBootProject
SpringBoot之web进阶，人类基因芯片程序-提升篇
https://github.com/bennyrhys/GirlPlus-SpringBootProject

+ 订阅