JAVA常见算法题(三十五)

时间:2017-09-18 23:15:03   收藏:0   阅读:302

判断一个整数能被几个9整除。

public static void main(String[] args) {
        f(729); f(
730); } public static void f(int n) { int tmp = n; int count = 0; for (int i = 0; tmp % 9 == 0;) { tmp = tmp / 9; count++; } System.out.println(n + "能够被 " + count + "个9整除。"); }

 

 

技术分享

 

原文:http://www.cnblogs.com/mr-wuxiansheng/p/7545711.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!