彩票生成器(java)

Lottery.java

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class Lottery{
    public List getHeadLottery(){
        List list = new ArrayList();
        String lotteryNumber = "";
        for(int i=0;i<36;i++){
            if(i<10){
                list.add("0"+i+" ");
            }
            else{
                list.add(""+i+" ");
            }
        }
        int roundIndex = 0;
        List lotterylist = new ArrayList();
        for(int j=0;j<5;j++){
            int count = list.size();
            Random r = new Random();
            roundIndex = r.nextInt(count);
            lotteryNumber = list.get(roundIndex);
            lotterylist.add(lotteryNumber);
            list.remove(roundIndex);
        }
         Collections.sort(lotterylist);
         return lotterylist;
    }

    public List getRearLottery(){
        List list = new ArrayList();
        String lotteryNumber = "";
        for(int i=0;i<13;i++){
            if(i<10){
                list.add("0"+i+" ");
            }
            else{
                list.add(""+i+" ");
            }
        }
        int roundIndex = 0;
        List lotterylist = new ArrayList();
        for(int j=0;j<2;j++){
            int count = list.size();
            Random r = new Random();
            roundIndex = r.nextInt(count);
            lotteryNumber = list.get(roundIndex);
            lotterylist.add(lotteryNumber);
            list.remove(roundIndex);
        }
         Collections.sort(lotterylist);
         return lotterylist;
    }

    public void generateLottery(String groupNum){
        int groupNumber = 0;
        groupNumber = Integer.parseInt(groupNum);
        StringBuilder sbuilder = new StringBuilder();
        for(int i=0;i startList = getHeadLottery();
            List endList = getRearLottery();
            for(int j=0;j

LotteryTest.java

import java.util.Scanner;

public class LotteryTest{
    public static void main(String[] Args){
        Lottery lottery = new Lottery();
        Scanner scan = new Scanner(System.in);
        System.out.println("Please input the number of lottery group(s) that you want to generate : ");
        String groupNum = scan.nextLine();
        lottery.generateLottery(groupNum);
    }
}

你可能感兴趣的:(java基础)