java的for循环

在求最小公倍数时遇到了,for循环简写的问题,好久没有动手写代码,手有点生,,

如果没有for循环中间的语句,也就是条件语句那就相当于一直进行循环,直到循环结束

 long f = zmgys(a,b);//调用求最小公倍数数的方法
 System.out.println("最小公倍数:"+f);
/**
求最小公倍数
**/
 private static long zmgys(int a, int b) {
        int max = a>b? a : b;
        for(long i=max; ;i+=max) {
            //i能同时被a和b整除
            if(i%a==0 && i%b==0) {
                return i;
            }
        }

    }

猜你喜欢

转载自blog.csdn.net/azhiyou/article/details/126913917
今日推荐