package method.homework;
import java.util.Random;
public class SuiJi {
public static void jiangJin() {
int[] arr = {2, 588, 888, 1000, 10000};
//count是用来定义奖金被抽出的个数,count=5时,抽奖结束
int k, count = 0;
//定义一个number可以查看总共抽了多少次
//int number=0;
Random r = new Random();
for (int i = 0; count < 5; i++) {
k = r.nextInt(5);
//System.out.println(k);
// number++;
if (i == 0) {
System.out.println(arr[k] + "的奖金被抽出");
count++;
arr[k] = 0;
} else if (arr[k] != 0) {
System.out.println(arr[k] + "的奖金被抽出");
count++;
arr[k] = 0;
}
}
//System.out.println("抽了"+number+"次奖");
}
public static void main(String[] args) {
jiangJin();
}
} |
|