import java.util.Random;
public class Test12 {
public static void main(String[] args) {
/*需求:一个大V直播抽奖,奖品是现金红包,分别有{2,588,888,1000,10000}五个奖金。
请使用代码模拟抽奖,打印出每个奖项,奖项的出现顺序要随机且不重复。
打印效果如下:(随机顺序,不一定是下面的顺序)
888元的奖金被抽出
588元的奖金被抽出
10000元的奖金被抽出
1000元的奖金被抽出
2元的奖金被抽出
*/
int[] raffle={2,588,888,1000,10000};
int[] temp=new int[raffle.length];
getRaffle(raffle,temp);
}
public static void getRaffle(int[] raffle, int[] temp){
Random r = new Random();
int count=0;
while(count<=5) {
int ran=r.nextInt(raffle.length);
if(temp[ran]==raffle[ran]){
continue;
}
else {
temp[ran]=raffle[ran];
System.out.println(raffle[ran]+"元的奖金被抽出");
count++;
}
}
}
}
一个大V直播抽奖,奖品是现金红包,分别有{2,588,888,1000,10000}五个奖金。 请使用代码模拟抽奖,打印出每个奖项,奖项的出现顺序要随机且不重复。
最新推荐文章于 2024-01-24 14:07:37 发布