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();
}
}