java 求最大公约数

package com.oop;

public class gongyueshu {
	public static void main(String[] args) {
		int result = getCommonDivisor(60, 120);
		System.out.println(result);
	}
	
	public static int getCommonDivisor(int x, int y) {
		if(y == 0) {
			return x;
		}
		int z = x % y;
		return getCommonDivisor(y, z);
	}
}
posted @ 2022-06-20 08:41  wjxuriel  阅读(25)  评论(0)    收藏  举报