[JAVA]数组 求代码解释
求代码解释
public class CouponCollector {
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
boolean[] found = new boolean[N];
int cardcnt = 0;
int valcnt = 0;
while (valcnt < N) {
int val = (int) (Math.random() * N);
cardcnt++;
if (!found[val]) valcnt++;
found[val] = true;
}
System.out.println(cardcnt);
}
}
IT衡
2015/05/27 12:06- new
- string
- 点赞
- 收藏
- 回答
4个回复
