所以我需要得到25到75之间的随机数,我尝试了两件事:
System.out.println(random.nextInt(75)+25);
System.out.println((int)(Math.random()*75) + 25);
据我所知,我在两行中写的“75”应该是我得到的最大数字,“25”应该是最小的数字。但是,我得到了这样的数字:
84,94,82,79,98 // these are only the numbers that went out of range
我想我误解了nextInt和Math.random的规则。我如何获得我想要的数字(在25到75之间)?
精慕HU
九州编程
饮歌长啸
随时随地看视频慕课网APP
相关分类