java|最大公约数_辗转相除法
public class 最大公约数_辗转相除法 { /**
* @param args
*/
public static int getGreatestCommonDivisorV2(int a, int b) {
int big = a > b ? a : b;
int small = a < b ? a : b;
if (big % small == 0) {
return small;
}
return getGreatestCommonDivisorV2(big % small, small);
} public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(getGreatestCommonDivisorV2(25, 5));
System.out.println(getGreatestCommonDivisorV2(100, 80));
}}
推荐阅读
- JAVA(抽象类与接口的区别&重载与重写&内存泄漏)
- 事件代理
- Java|Java OpenCV图像处理之SIFT角点检测详解
- java中如何实现重建二叉树
- 数组常用方法一
- 【Hadoop踩雷】Mac下安装Hadoop3以及Java版本问题
- Java|Java基础——数组
- RxJava|RxJava 在Android项目中的使用(一)
- java之static、static|java之static、static final、final的区别与应用
- Java基础-高级特性-枚举实现状态机