import java.util.Scanner;
import java.util.Random;
//键盘录入观众姓名
//存储观众姓名
//展示观众姓名(遍历)
//随机选出一名观众,并打印观众的姓名
public class chose {
static String[] arr = new String[3];
public static void main(String[] args) {
Random r = new Random();
int num = r.nextInt();
save();
show();
redom();
}
//随机选择并输出
public static void redom() {
Random r = new Random();
int num = r.nextInt(2)+1;
String a=null;
switch (num){
case 1:
a=arr[0];
break;
case 2:
a=arr[1];
break;
case 3:
a=arr[2];
break;
}
System.out.println("这次的幸运观众是:"+a);
}
//展示观众姓名
public static void show() {
for (int i = 0; i < arr.length; i++) {
System.out.println("第" + (i + 1) +
"位观众的姓名是:" + arr[i]);
}
}
//存储
public static void save() {
String name = null;
Scanner sc = new Scanner(System.in);
for (int i = 0; i < arr.length; i++) {
System.out.println("请输入第" + (i + 1) + "位观众的姓名:");
name = sc.next();
arr[i] = name;
}
}
}
04-08
1970
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-22
3556
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-04
3102
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-11
1365
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交