考试题

来源:互联网 发布:北京seo实战培训 编辑:程序博客网 时间:2024/04/29 11:04
package com.UUU.util;

public class KaoShi {

    public static void main(String[] args) {

        for (int i = 0; i < 100; i++) {
            System.out.print(random9() + " ");
        }
    }

    /**
     * 根据random8,生成[1,9]之间的随机数
     *
     * @return
     */
    private static int random9() {
        int x;
        do {
            x = random8() * 8 + random8();
        } while (x == 8 * 8 - 1);
        return x % 9 + 1;
    }

    /**
     * 生成[1,8]之间的随机数
     *
     * @return
     */
    private static int random8() {
        int r = (int) (Math.random() * 8) + 1;
        return r;
    }

}

0 0
原创粉丝点击