DESKTOP-0FT47VC_20200911-罗贤丞

问题

输出1000以内的孪生素数对。

解决

public class TwinPrime {

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

    public static void main(String[] args) {

        TwinPrime t = new TwinPrime();
        for (int i = 2; i < 1000; i++) {
            if (t.sort(i) && t.sort(i + 2)) {
                System.out.println(i + " " + (i + 2));
            }
        }

    }

}

吐槽

天气还是纳摩的的炎热啊。

标签


© 2021 成都云创动力科技有限公司 蜀ICP备20006351号-1