码迷,mamicode.com
首页 > 其他好文 > 详细

题目一:编写一个可以 获取任意指定范围内的随机数

时间:2017-08-10 01:11:42      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:math   and   int   --   随机   tar   实现   art   代码   

分析:

     键盘录入数据来指定范围:[start,end]

       String start =sc.next();

       String end=sc.next();

   实现代码:

   public static int getRoundomNum(int start, int end){

           //(int)(Math.random()*100)+1 ;//[1,100]   ---(1)

           //(int) (Math.random()*end)+start;//[start,end+start-1]  --(2)

             //由式(1)(2可以推出式(3):

           return  (int)(Math.random()*(end-start+1))+start;//[start,end]   --(3)

   }

题目一:编写一个可以 获取任意指定范围内的随机数

标签:math   and   int   --   随机   tar   实现   art   代码   

原文地址:http://www.cnblogs.com/yuefeng123/p/7336973.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!