gpt4 book ai didi

java - 通过函数返回多个数组(处理)

转载 作者:行者123 更新时间:2023-12-01 09:50:52 27 4
gpt4 key购买 nike

所以我需要从进程中的函数返回多个数组。问题是我不知道要使用哪个函数值? (例如 int 函数、字符串函数等)另外,我如何返回多个值?我需要从 arrayGen() 到barriers() 的发送barrierx 和barriery。感谢您的帮助!

最终:

int barriers(){
if (R == 1){
while (size>0){
barrierx[size-1] = randomInt(512);
barriery[size-1] = randomInt(512);
size = size - 1;
}

while (sizeC>0){
ellipse( barrierx[sizeC-1], barriery[sizeC-1], 100, 100);
sizeC = sizeC - 1;
}
sizeC = sizeB;
R = 0;
}
return 5;
}

int arrayGen(){
int size = randomInt(11);
int sizeB = size;
int sizeC = size;

int[] barrierx = new int[size];
int[] barriery = new int[size];
}

编辑:

int arrayGen(){

int size = randomInt(11);
int sizeB = size;
int sizeC = size;
int[] result = new int[2];

int[] barrierx = new int[size];
int[] barriery = new int[size];

while (size>0){
barrierx[size-1] = randomInt(512);
barriery[size-1] = randomInt(512);
size = size - 1;
}


result[0] = barrierx;
result[1] = barriery;
return result;
}

类型不匹配无法从 int[] 转换为 int

最佳答案

定义一个包含您需要的所有数据字段的类。然后返回该类的一个对象。

关于java - 通过函数返回多个数组(处理),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37613165/

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