以一些特出符号分隔的例子可用

public static void main(String [] args)
{
Scanner sc = new Scanner(System.in);
int a1,c1;
String data = sc.next();
String num [] = data.split("/");
int a = Integer.parseInt(num[0]);
int c = Integer.parseInt(num[1]);
a1 = a;
c1 = c;
int t;
while(c1!=0)
{
t = a1%c1;
a1 = c1;
c1 = t;
}
a = a/a1;
c = c/a1; //找最大公约数   (最小公倍数 = 两数乘积 / 最大公约数)
System.out.printf("%d/%d\n",a,c);
}

posted @ 2022-03-28 20:44  heartbeat111  阅读(34)  评论(0)    收藏  举报