我是初学者程序员,这是我第一次在这里提问,如果对格式有任何担心,我会感到非常抱歉.首先,感谢您的回答,感谢您的耐心和赦免.
实际上问题是“循环直到找到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);*/
}