java 求最大公约数

Posted sgbe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 求最大公约数相关的知识,希望对你有一定的参考价值。

public class Main
public static void main(String[] args)

System.out.println(gcd(4,8));

//辗转相除法
public static int gcd(int x, int y)
if(y == 0)
return x;
else
return gcd(y,x%y);

以上是关于java 求最大公约数的主要内容,如果未能解决你的问题,请参考以下文章