集册 Java实例教程 欧几里得的最大除数(GCD)

欧几里得的最大除数(GCD)

欢马劈雪     最近更新时间:2020-01-02 10:19:05

512
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
欧几里得的最大除数(GCD)

public class Main {
/* 
*来 自
 时代Java
*/

    public static void main(String[] arg) {

        int a = 32;

        int b = 24;

        System.out.println("Computing GCD(" + a + "," + b + ")");


        while (a != b) {

            if (a > b) a = a - b;

            else b = b - a;

        }

        // Display to console

        System.out.println("Greatest common divisor is " + a);

    }

}