- //樂透開獎-good
- double rd;//int Result;
-
- int []lottery = new int[]{1,2,3,4,5,6,7,8,9,10};
- int rdindex = 0,temp = 0;
-
- for(int i=0 ; i<10 ; i++)
- {
- System.out.println(lottery[i]);
- }
-
-
- //隨機交換陣列值
- for(int i=0 ; i<10 ; i++)
- {
- rd = Math.random()*10;
- rdindex = (int)rd; //隨機取位置0~9
-
- //兩個位置的值交換 lottery[i] lottery[?]
- temp = lottery[i];
- lottery[i] = lottery[rdindex];
- lottery[rdindex] = temp;
- }
-
- //把整個lottery[]陣列列印出來
- for(int i=0 ; i<10 ; i++)
- {
- System.out.println(lottery[i]);
- }
-
-
- System.out.println("三個開獎號為:"+lottery[0]+","+lottery[1]+","+lottery[2]);
-
複製代碼 |