循环

作者: 陈皮丨阿四 | 来源:发表于2018-11-29 21:19 被阅读0次

package com.neuedu.chapter4_1026;

public class Demo7 {

public static void main(String[] args) {

// 模拟35选7:在控制台打印7个1-35之间的数字,不能重复

// double d = Math.random();// [1,36)

// System.out.println(d);

boolean arr[] = new boolean[35];

for(int i = 0;i < 7;i++) {

int random = (int)(Math.random()*35+1);

// 判断是否生成过

if(arr[random-1]) {

i--;

}

else {

arr[random-1] = true;

System.out.print(random+" ");

}

}

}

}

相关文章

网友评论

      本文标题:循环

      本文链接:https://www.haomeiwen.com/subject/rijqcqtx.html