代码拉取完成,页面将自动刷新
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 Áõ˼Զ");
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。