随机 1–10 java
添加链接描述
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30package com.mindskip.xzs.utility; public class RandomUtil { // 方法二:Math.random() // 返回带有正号的{@code double}值,该值大于*等于或等于{@code 0.0}并且小于{@code 1.0} public static int randomInt(int from ,int to){ // java 随机 1 到 10 // 方法二:Math.random() // 返回带有正号的{@code double}值,该值大于*等于或等于{@code 0.0}并且小于{@code 1.0} // int num2 = (int) (Math.random()*10+1); int num2 = (int) (Math.random()*to+from); // System.out.println(num2); //———————————————— // 版权声明:本文为CSDN博主「骑着蜗牛ひ追导弹'」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 // 原文链接:https://blog.csdn.net/qq_45797116/article/details/115007744 // return num2; } public static void main(String[] args) { // int i = RandomUtil.randomInt(1, 10); // 4,10,4,4,8,7,10,3,5,7, for (int j = 0; j <10 ; j++) { int i = RandomUtil.randomInt(1, 10); System.out.print(i+","); } } }
最后
以上就是大力水蜜桃最近收集整理的关于随机 1--10 java的全部内容,更多相关随机内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复