java实现约分

public static void main(String[] args) {
		int a = 7, b = 100, gongyinshu = 1;
		int smaller = a > b ? b : a;
		for (int i = 1; i <= smaller; i++) {
			if (a % i == 0 && b % i == 0) {
				gongyinshu = i;
			}
		}
		System.out.println(a + "和" + b + "的最小公因数为:" + gongyinshu);
		System.out.println(a + "/" + b + "约分得:" + a / gongyinshu + "/" + b / gongyinshu);
	}

你可能感兴趣的:(学习,JAVA,java,语言)