Java list fill_Java List:当我调用Arrays.fill()来填充数组时...

我是初学者程序员,这是我第一次在这里提问,如果对格式有任何担心,我会感到非常抱歉.首先,感谢您的回答,感谢您的耐心和赦免.

实际上问题是“循环直到找到4种不同颜色的扑克牌”.我使用数组来表示卡号,并使用数组来表示它们的颜色.

并且我用for语句填充cardNo数组,值从1到4,但它显示为0,我不知道为什么,我认为这就是问题发生的地方,这就是我的所有代码.

public static void collect() {

int num=0;

//represent 52 Poker Cards

int [] cardNo=new int[52];

List list=new ArrayList<>();

// `int[] color=new int[4]` to represent 4 colors, so the value

// of cardNo[] elements is the Color.

for(int i=0;i<4;i++) {

Arrays.fill(cardNo, i*13, (i+1)*13-1, i+1);

}

for(int n:cardNo) {

list.add(n);

}

Collections.shuffle(list);

// I use this for statement to check if it's worry with Arrays.fill(),

// or it's about the list.add().

for(int i:cardNo) {

System.out.print(i+" ");

}

System.out.println(list);

/*int[] color=new int[4];

while(color[0]==0||color[1]==0||color[2]==0||color[3]==0) {

int n=(int)(Math.random()*53);

color[(int) list.get(n)-1]++;

num++;

}

System.out.println("Number of picks: "+num);*/

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值