⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asd.txt

📁 抽奖程序可自定人物属性抽奖程序可自定人物属性
💻 TXT
字号:
import java.util.*;   
//抽奖程序测试   
class TestAward    
{   
    public static void main(String[] args)    
    {   
        //声明al,保存中奖者   
        ArrayList al = new ArrayList();   
        //声明result,保存所有参加抽奖的人   
        ArrayList result = new ArrayList();   
        //添加五个人,参加测试   
        result.add("张三");   
        result.add("李四");   
        result.add("王五");   
        result.add("赵六");   
        result.add("阮七");   
        //五个人中,将有三个人中奖   
        for(int i = 0; i < 3; i++ ){   
        //定义一个随机索引   
        /*  
        int j = (int)Math.round(Math.random()*result.size());  
        //防止越界  
        if(j==result.size()){  
            j--;  
        }*/   
        //这个方法好!   
        Random rnd = new Random();        
        int j = rnd.nextInt(result.size());   
        //取出中奖者   
        String s = (String) result.get(j);   
        //从参加抽奖的集合中移除   
        result.remove(s);   
        //增加到al中   
        al.add(s);   
        }    
        //打印测试   
        System.out.print(al.toString());   
    }   
}  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -