int count=0;
for (int i = 0; i < 10; i++) {
int num = (int)(Math.random()*99);
if (num<50) {//小于50 就加一下外面的统计数
count++;
}
System.out.println("随机数=="+num );
}
System.out.println("循环10次的随机数小于50的个数有=="+count);
实现思路:生成50-100之间的随机数(包括50,包含100),之后循环k次分别输出即可:int k = 5;for(int i = 0;i
int[] iny = new int[10];
Random random = new Random();
int sum = 0;
for(int i = 0; i < iny.length; i++){
iny[i] = random.nextInt(99);
if(iny[i] < 50){
sum++;
}
}
System.out.println(sum);
System.out.println(Arrays.toString(iny));
public static void main(String[] args) {
// TODO Auto-generated method stub
int count = 0;
for (int i = 0; i < 10; i++) {
int number = (int) (Math.random() * 99);
if (number < 50) {
count++;
}
System.out.print(number + " ");
}
System.out.println("小于50的数字有" + count + "个");
}