gpt4 book ai didi

java - 返回数组类

转载 作者:行者123 更新时间:2023-12-02 11:15:30 25 4
gpt4 key购买 nike

我有一个问题!我不知道如何返回数组?我想使用 get 和 set。

 TypeOfWater[] waters = returnTypes1();

public String[] getTypeOfWater()
{
return waters;//How can I rerutn array???
}


private static TypeOfWater[] returnTypes1()
{
TypeOfWater[] type = new TypeOfWater[4];
type[0] = new TypeOfWater();
type[0].name = "1)Fanta";
type[0].cost = 11;

type[1] = new TypeOfWater();
type[1].name = "2)Coca";
type[1].cost = 12;

type[2] = new TypeOfWater();
type[2].name = "3)Sprite";
type[2].cost = 14;

type[3] = new TypeOfWater();
type[3].name = "4)Orange juice";
type[3].cost = 22;

return type;
}

请帮帮我。我是 Java 编程新手。

最佳答案

你应该改变

public String[] getTypeOfWater()
{
return waters;//How can I rerutn array???
}

对于

public TypeOfWater[] getTypeOfWater()
{
return waters;//How can I rerutn array???
}

关于java - 返回数组类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50310876/

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