1-36随机生成6个不重复的数
生活随笔
收集整理的這篇文章主要介紹了
1-36随机生成6个不重复的数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 import java.util.Random;
2
3 public class Homework0511 {
4
5 public static void main(String[] args) {
6 // TODO 自動生成的方法存根
7
8 //抽獎 1-36 不重復 6個
9
10 Random rand=new Random();
11 int arr[]=new int[6];
12 for(int i=0;i<6;i++)
13 {
14 arr[i]=rand.nextInt(36);
15 for(int j=0;j<i;j++)
16 {
17 if(arr[i]==arr[j])
18 {
19 i--;
20 break;
21 }
22 }
23
24
25 }
26 for(int i=0;i<6;i++)
27 {
28 System.out.println(arr[i]+1);
29 }
30
31
32
33
34 }
35
36 }
運行結果:
轉載于:https://www.cnblogs.com/miss123/p/5481313.html
總結
以上是生活随笔為你收集整理的1-36随机生成6个不重复的数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL 重置自增列的值 批量处理
- 下一篇: 探索式软件测试—Exploratory