import javax.swing.* ; import java.util.*; public class EZLottery { private static int allNum[]=new int[42]; public static void main ( String args [] ) { for (int i=0;i < class="blue">//把42顆彩球裝箱 allNum[i]=++i; } String output=""; int[] luckyNum = getLuckyNum(); Arrays.sort(luckyNum); for (int i = 0; i < luckyNum.length-1; i++) { output += "【" + luckyNum[i] + "】"; } JOptionPane.showMessageDialog ( null , output + "特別號【" + luckyNum[6] +"】" );//秀出結果 System.exit ( 0 ) ; } private static int[] getLuckyNum() { //將前七個彩球隨機打亂 int selectNum[] = new int[7]; for (int i = 0; i < selectNum.length; i++) { int num = (int)(allNum.length * Math.random()); int tmp = allNum[i]; allNum[i] = allNum[num]; allNum[num] = tmp; } for (int i = 0; i < selectNum.length; i++) { selectNum[i] = allNum[i]; } return selectNum; } }
|
沒有留言:
張貼留言