1 Star 0 Fork 0

年少不如初丶 / java201621123079

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Ration.java 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
package week03;
import java.util.Scanner;
class Ration {
private int v1;
private int v2;
private static int gcd(int m,int n)
{
int t;
while(m%n!=0)
{
t=n;
n=m%n;
m=t;
}
return n;
}
public Ration() {}
public Ration(int v1 , int v2)
{
this.v1=v1;
this.v2=v2;
}
public static void add(Ration T1,Ration T2 ,Ration T3)
{
int y=T1.v2*T2.v2;
int x1=T1.v1*T2.v2;
int x2=T2.v1*T1.v2;
int n=gcd(y,x1+x2);
T3.v1 = (x1+x2)/n;
T3.v2 = y/n;
}
public static void Multiply(Ration T1,Ration T2 ,Ration T3)
{
T3.v1 = T1.v1*T2.v1;
T3.v2 = T1.v2*T2.v2;
int n = gcd(T3.v2,T3.v1);
T3.v1/=n;
T3.v2/=n;
}
public static void Get(Ration t)
{
System.out.println(t.v1+" "+t.v2);
}
public static void Get1(Ration t,int i)
{
if(i==1) System.out.println(t.v1);
else System.out.println(t.v2);
}
public static class Main {
public void main(String[] args) {
Scanner sc = new Scanner(System.in );
Ration a = new Ration(sc.nextInt(),sc.nextInt());
Ration b = new Ration(sc.nextInt(),sc.nextInt());
Ration c = new Ration();
Ration d = new Ration();
Ration.add(a,b,c);
Ration.Get(c);
Ration.Multiply(a,b,d);
Ration.Get(d);
Ration.Get1(a,sc.nextInt());
sc.close();
System.out.println("201621123079 Áõ˼Զ");
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mayunlsyuan/java201621123079.git
git@gitee.com:mayunlsyuan/java201621123079.git
mayunlsyuan
java201621123079
java201621123079
master

搜索帮助