用Java编写一个,随机选择一个历史美女的代码案例,要求美女数量20个
时间: 2024-06-11 15:05:51 浏览: 14
import java.util.Random;
public class ChooseBeauty {
public static void main(String[] args) {
String[] beauties = {"貂蝉", "王昭君", "杨贵妃", "西施", "貂蝉", "王昭君", "杨贵妃", "西施", "貂蝉", "王昭君", "杨贵妃", "西施", "貂蝉", "王昭君", "杨贵妃", "西施", "貂蝉", "王昭君", "杨贵妃", "西施"};
Random rand = new Random();
int index = rand.nextInt(20);
System.out.println("今天我们选择的历史美女是:" + beauties[index]);
}
}
相关问题
用Java编写一个,随机选择一个历史美女的代码案例,要求美女数量50个
public class RandomBeautySelector {
public static void main(String[] args) {
String[] beauties = new String[50];
beauties[0] = "西施";
beauties[1] = "王昭君";
beauties[2] = "貂蝉";
//... 其他美女名称
beauties[49] = "杨贵妃";
int randomIndex = (int) (Math.random() * 50);
System.out.println("今天的历史美女是:" + beauties[randomIndex]);
}
}
用Java编写一个,随机选择一个历史美女的代码案例,要求美女数量20个不能重复
/**
* 随机选择一个历史美女的代码案例
* 要求美女数量20个不能重复
*/
import java.util.Random;
public class RandomBeauty {
public static void main(String[] args) {
String[] beauties = {"王昭君", "貂蝉", "杨玉环", "西施", "兰陵王妃", "赵飞燕", "梁山伯与祝英台", "李师师", "秦淮八艳", "花木兰", "孟姜女", "潘金莲", "西门庆", "尉迟恭", "张三丰", "黄飞鸿", "乔峰", "段誉", "虚竹", "杨过"};
Random random = new Random();
int index = random.nextInt(20);
String beauty = beauties[index];
System.out.println("今天您的幸运美女是:" + beauty);
}
}
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)