gpt4 book ai didi

java - 将数组的特定对象复制到特定位置的另一个相同类型数组的方法

转载 作者:行者123 更新时间:2023-12-01 13:32:12 26 4
gpt4 key购买 nike

我只想按卡片类型“黑桃、红心、梅花、方 block 四张之一”对一系列卡片进行排序,即黑桃排在第一位

我创建了新数组,请解决它

private static void colorSort(Card temp[]){      
Card arr[];
arr = new Card[13];
int loc=0;
for(Card x: temp){
if(x.cardType=="Spade"){
arr[0] = temp[x]; //this line giving error that "can't convert Card to int"`
loc++;
}
}
}

最佳答案

您不能通过对象(而不是整数)对数组进行索引 - 您必须使用 int

但是你不想访问数组,你想在循环中使用对象:

arr[0] = x;  

关于java - 将数组的特定对象复制到特定位置的另一个相同类型数组的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21507601/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com