36选7小程序

package com.math.test;

import java.util.Arrays;
import java.util.Random;

public class MathTest {

    public static void main(String[] args) {
        
        int offset = 0;
        int[] data = new int[7];
        Random r = new Random();
        while(offset < 7){
            int i = r.nextInt(37);
            if(!isRepeat(data,i)){
                data[offset++] = i;
            }
        }
        
        Arrays.sort(data);
        for(int m = 0; m < data.length; m++){
            System.out.print(data[m] + ",");
        }
    }
    
    
    public static boolean isRepeat(int[] data, int num){
        if(num == 0){
            return true;
        }
        for(int i = 0; i < data.length; i++){
            if(data[i] == num){
                return true;
            }
        }
        return false;
    }
}

 

posted @ 2015-12-16 16:43  finalboss1987  阅读(188)  评论(0编辑  收藏  举报