以一些特出符号分隔的例子可用
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);
}

浙公网安备 33010602011771号