前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >java 名单随机抽取

java 名单随机抽取

作者头像
花狗Fdog
发布2020-10-28 14:33:55
1.5K0
发布2020-10-28 14:33:55
举报
文章被收录于专栏:花狗在Qt
代码语言:javascript
复制
package number;
import java.util.Scanner;
public class chapter03 {
	public static void main(String[] args) {
		Scanner s_num = new Scanner(System.in);
		System.out.println("请输入人数:");
		int sum = s_num.nextInt();
		String[] stu_array = new String[sum];
		//循环输入姓名
		Scanner s_name = new Scanner(System.in);
		for(int i = 0;i < stu_array.length;i++){
			System.out.println("请输入第"+(i+1)+"名同学:");
			stu_array[i] = s_name.next();
		}
		System.out.println("人员名单初始化已完成,是否开始抽取,(1/2)抽取/取消");
		Scanner s_int = new Scanner(System.in);
		if(1 == s_int.nextInt()){
			//产生随机数
			int num = (int)(Math.random()*(stu_array.length)); 	
			System.out.println("抽取的同学是:"+ stu_array[num]);
		}else{
			System.out.println("取消成功");
		}
	}
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/05/27 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档