本帖最後由 謝瀞儀 於 2016-11-5 11:56 編輯
- package messing1;
- import java.util.Random;
- public class messing01
- {
- public static void main(String[] args)
- {
- Random r =new Random();
- int [] num = new int[10];
- for(int i=0;i<10;i++)
- {
- num[i]=r.nextInt(10)+1;
- for(int j=0;j<i;)
- {
- if(num[i]==num[j])
- {
- num[i]=r.nextInt(10)+1;
- j=0;
- }
- else
- j++;
- System.out.println(r.nextInt(10));
- }
- }
- }
- }
複製代碼 |