JAVA学习--约分最简分式

JAVA学习–约分最简分式

输入:在一行中给出一个分数,分子和分母中间以斜杠/分隔,

例如:输入 66/120
输出 11/20

public class Main {

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);
}

}

你可能感兴趣的:(java初学,java)