设计一个福利彩票类WelfareLottery,成员方法GenerateLottery能够模仿福利彩票23选5,随机生成5个不同的1-23之间的整数,并且不能重复。成员方法PrintLottery能够

package 泛型与集合类;

import java.util.Random;

import java.util.*;

public class WelfareLottery {

       Random r = new Random();

       List<Integer>data=new ArrayList<Integer>();

      

       public void GenerateLottery(){

              for(int i=0;i<5;i++){

                      Integer random = Integer.valueOf(r.nextInt(23));

                   if (!data.contains(random)){

                       data.add(random);

                       continue;

                   }

                   i--;

               }

       }

       void PrintLottery(){

              Iterator<Integer> it =data.iterator();

                while(it.hasNext()){

                       System.out.println(it.next());

                }

       }

}

 

package 泛型与集合类;

 

public class text {

 

       public static void main(String[] args) {

              // TODO Auto-generated method stub

              WelfareLottery w=new WelfareLottery();

              w.GenerateLottery();

              w.PrintLottery();

 

       }

 

}

 

 

                                                             

 

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 游动-白 设计师: 上身试试
应支付0元
点击重新获取
扫码支付

支付成功即可阅读