2011年11月7日 星期一

JAVA 大樂透 呼叫靜態方法

 

 

 

 

public class 魏功豪_callststic {
	public static void main(String[] args) {
		int betTimes = 10;
		int allBalls = 49;

		int [] getAllBalls;
		int [] getSixBalls;
		int [] getOrderByDESC;

		for (int bt = 1; bt <= betTimes; bt++) {
			getAllBalls = 魏功豪_callststic.functiondoArrBoxAll(allBalls);//長度[49]陣列傳進getAllBalls
			getSixBalls = 魏功豪_callststic.functionRandomGetBall(getAllBalls);//長度[6]陣列傳進getSixBalls
			getOrderByDESC = 魏功豪_callststic.functionOrderByDESC(getSixBalls);//長度[6]陣列傳進getOrderByDESC

			System.out.print("第" + bt + "注\t");
			for (int i = 0; i <= 5; i++) {
				System.out.print((getOrderByDESC[i] < 10) ? " " + getOrderByDESC[i] + ",\t" : getOrderByDESC[i] + ",\t");
			}
			System.out.print("\n");
		}
	}

	public static int [] functiondoArrBoxAll(int howManyAllBalls) {
		int [] doArrBoxAll = new int [howManyAllBalls];
		for (int i = 0; i <= howManyAllBalls - 1; i++) {
			doArrBoxAll[i] = i + 1;
		}
		return doArrBoxAll;//製造長度[49]陣列傳回,最初的49顆球陣列
	}

	public static int [] functionRandomGetBall(int [] arrOriginal) {
		int getballs = 6;
		int [] doArrSixBall = new int [getballs];

		for (int times = 1; times <= getballs; times++) {
			int randomTakeOneBall = (int)(Math.random()*arrOriginal.length);
			doArrSixBall[times-1] = arrOriginal[randomTakeOneBall];
			int [] arrNew = new int [arrOriginal.length - 1];
			for (int i = 0; i <= (arrOriginal.length - 1) - 1; i++) {
				arrNew[i] = (i < randomTakeOneBall) ? arrOriginal[i] : arrOriginal[i + 1];
			}
			arrOriginal = arrNew;
		}

		return doArrSixBall;//製造長度[6]陣列傳回,隨機取6球,未排列
	}

	public static int [] functionOrderByDESC(int [] arrRandomSixBall) {
		int temp;
		for (int i = 0; i < 6; i++) {
			for (int j = i; j < 6; j++) {
				if (arrRandomSixBall[i] < arrRandomSixBall[j]) {
					temp = arrRandomSixBall[j];
					arrRandomSixBall[j] = arrRandomSixBall[i];
					arrRandomSixBall[i] = temp;
				}
			}
		}
		return arrRandomSixBall;//製造長度[6]陣列傳回,將6球照大小排列
	}
}

沒有留言:

張貼留言