import java.util.Random;
import java.util.Scanner;
/**
* 測試彩票類
* @author doulmi
*
*/
public class LotteryDemo {
public static void main( String[] args ) {
Scanner scanner = new Scanner( System.in );
System.out.print( "請輸入要購買的註數:" );
System.out.println();
int buyN = 0;
if ( scanner.hasNextInt() ) {
buyN = scanner.nextInt();
} else {
System.out.println( "請輸入正確的數字" );
}
for ( int i = 0; i < buyN; i ++ ) {
Lottery lot = new Lottery();
lot.generate();
System.out.print( "第" );
System.out.print( i );
System.out.print( "註" );
lot.printData();
}
}
}
/**
* 彩票類
* @author Administrator
*
*/
class Lottery {
private static final int NUM_TO_GETOUT = 7;
//能產生的最大數值為99
private static final int MAX_NUM = 35;
public ArrayList< Integer > list;
private int[] result;
public Lottery() {
list = new ArrayList< Integer >();
for ( int i = 1; i <= MAX_NUM; i ++ ) {
list.add( i );
}
result = new int[ NUM_TO_GETOUT ];
}
public void generate() {
Random r = new Random();
for ( int i = 0; i < NUM_TO_GETOUT; i ++ ) {
result[ i ] = list.remove( r.nextInt( list.size() ) );
}
}
/**
* 關於票頭的打印。。我不知道票頭是什麽。
*/
public void pringTitle() {
}
/**
* 實現號碼的打印
*/
public void printData() {
for ( int n : result ) {
System.out.print( n );
System.out.print( " " );
}
System.out.println();
}
}