public class Euclid { public static int euclid(int x, int y){ int p = x; int q = y; int temp = 0; while(q != 0){ temp = p; p = q; q = temp % q; System.out.printf("p: %d, q: %d\n", p, q); } return p; } public static void main(String[] args){ int e = euclid(Integer.parseInt(args[0]), Integer.parseInt(args[1])); System.out.printf("%d 和 %d 的最大公约数是:%d\n", Integer.parseInt(args[0]), Integer.parseInt(args[1]), e); }}
评论