当前位置:网站首页>How to randomly assign 1000 to 10 numbers
How to randomly assign 1000 to 10 numbers
2022-06-22 03:37:00 【Healthy brick carrier】
Cut the rope :
1. Declare an array , The length is 1000.
2. Produce random 9 A digital , Divide the array into 10 paragraph
3. The length of each segment adds up to 1000
The code implementation is as follows :
public static void main(String[] args) {
boolean[] arr = new boolean[1001];
for (int i = 0; i< 9; i++)
arr[(int)(Math.random()*1000)] = true;
int preNum = 0;
int sum = 0;
arr[arr.length - 1] = true;
for (int i = 0; i < arr.length; i++){
if (arr[i]) {
System.out.println(" Numbers :" + (i - preNum));
sum += i - preNum;
preNum = i;
}
}
System.out.println(sum);
}
Output example :
Numbers :65
Numbers :108
Numbers :116
Numbers :285
Numbers :1
Numbers :197
Numbers :49
Numbers :20
Numbers :17
Numbers :142
1000
边栏推荐
猜你喜欢
随机推荐
[网鼎杯 2018]Fakebook1 参考
作为接口的模板
2022.6.21-----leetcode. one thousand one hundred and eight
Select in golang concurrent programming
3000 yuan projector comparison and evaluation, dangbei D3x beats Jimi new Z6 x
剑指 Offer 68 - II. 二叉树的最近公共祖先
Talk about the Flink waterline
Mysql 45讲学习笔记(一)一条sql语句的执行
3000元投影仪对比评测,当贝D3X完胜极米NEW Z6 X
R data analysis: significance and practice of calibration curve and DCA curve in clinical prediction model
1299. replace each element with the largest element on the right
分析Iceberg合并任务解决数据冲突
[QNX Hypervisor 2.2用户手册]5.5 启动和使用Guest
Sword finger offer 68 - I. nearest common ancestor of binary search tree
倍福TwinCAT3中PLC程序变量定义和硬件IO关联
3DE robot suction cup grabbing box
微信小程序聊天 表情
webview报错
倍福 PLC 字符串类型string操作
策略模式









