【习题45】

作者: Xplorist | 来源:发表于2017-04-20 13:34 被阅读11次

【程序45】
题目:判断一个素数能被几个9整除

package com.brx.eg_41_50;

public class Test45 {
    public static void main(String[] args) {
        test();
    }

    public static void test() {
        for (int i = 1; i < 1000; i++) {
            if (test1(i)) {
                int count = 0;
                while (i % 9 == 0) {
                    count++;
                    i = i / 9;
                }
                System.out.println(i + "能被" + count + "个9整除");
            }
        }
    }

    public static boolean test1(int n) {
        for (int i = 2; i < n; i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }
}

相关文章

网友评论

    本文标题:【习题45】

    本文链接:https://www.haomeiwen.com/subject/tpclzttx.html