抽奖系统

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.Scanner;

public class cj {
Scanner sc=new Scanner(System.in);
int b;
public void coujiangperson(){
String name;
System.out.println("请输入抽取人的姓名");
name = sc.nextLine();
System.out.println("输入抽取编号");
b = sc.nextInt();
}
ArrayList c;
public ArrayList add(){
if(c==null){
c=new ArrayList();
for (int i=1;i<=200;i++){
c.add(i);
}
}
Collections.shuffle(c);
return c;
}

public void coujiang(){
Random r=new Random();
int a=r.nextInt(200);
if(b==a){
System.out.println("一等奖"+c.get(a)+"号");
c.remove(a);
System.out.println("二等奖"+c.get(a)+"号");
c.remove(a);}
else{
System.out.println("请不要灰心");
}

}

public static void main(String[] args) {
cj a=new cj();
a.coujiangperson();
a.add();
a.coujiang();
}
}

原文地址:https://www.cnblogs.com/136jin/p/5535730.html