A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© shijialong1111 中级黑马   /  2016-7-3 19:32  /  865 人查看  /  2 人回复  /   1 人收藏 转载请遵从CC协议 禁止商业使用本文

3.Math类中的random方法
   求5-20之间的随机数, for循环重复输出10次.

2 个回复

倒序浏览
public class Day07_3 {
        public static void main(String[] args) {
                //int ran = (int)(Math.random()*15+5);

                for (int i=1; i<=10; i++) {
                        int ran = (int)(Math.random()*16+5);
                                System.out.println(ran);
                }
        }
}
回复 使用道具 举报
import java.util.Random;
/*生成5至20之间的随机整数,for循环重复输出10次.*/
public class MyDemo6_Random {
    public static void main(String[] args) {
        Random rm = new Random();
         for(int i = 0; i<10; i++){
            int sj5 = rm.nextInt(16)+5;
            System.out.println(sj5 );
        }
    }
}
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马