用java写一个抽奖程序按s键开始否则输出错误随机抽奖 奖品为美国队长", "钢铁侠", "绿巨人", "蜘蛛侠", "黑寡妇", "鹰眼", "蝙蝠侠", "金刚狼", "泰迦奥特曼", "假面骑士zero one
时间: 2023-10-14 22:08:04 浏览: 122
用java写的抽奖程序
4星 · 用户满意度95%
好的,以下是用Java编写的抽奖程序:
```java
import java.util.Random;
import java.util.Scanner;
public class Lottery {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("按s键开始抽奖:");
String input = scanner.nextLine();
if (input.equals("s")) {
String[] prizes = {"美国队长", "钢铁侠", "绿巨人", "蜘蛛侠", "黑寡妇",
"鹰眼", "蝙蝠侠", "金刚狼", "泰迦奥特曼", "假面骑士zero one"};
Random random = new Random();
int index = random.nextInt(prizes.length);
System.out.println("恭喜您获得了:" + prizes[index]);
} else {
System.out.println("输入错误!");
}
}
}
```
阅读全文