gpt4 book ai didi

java - 错误信息找不到符号?

转载 作者:行者123 更新时间:2023-12-01 17:07:47 25 4
gpt4 key购买 nike

我正在尝试创建一个双字符串。我认为这是分配值的一种方法。我知道有更好的方法,但我的老师建议这样做。但是,当我将其放入时,我会收到每个错误,其中指出:

找不到符号 cellPhoneNumbers预计为“]”

最终我想做的是创建一个看起来像这样的图表

智利********瑞典*秘鲁****************

public class GraphNumbers
{
String[][] cellPhoneNumbers = new String[5][1];
cellPhoneNumbers[0][0] = "Chile";
cellPhoneNumbers[0][1] = "21";
cellPhoneNumbers[1][0] = "Sweden";
cellPhoneNumbers[1][1] = "11";
cellPhoneNumbers[2][0] = "Peru";
cellPhoneNumbers[2][1] = "33";
cellPhoneNumbers[3][0] = "Bulgaria";
cellPhoneNumbers[3][1] = "10";
cellPhoneNumbers[4][0] = "Guatemala";
cellPhoneNumbers[4][1] = "18";

}

为什么我会收到此消息?

最佳答案

某些代码必须放置在方法中,例如:

public class GraphNumbers
{
//changed the size of the array so you could do what you want
//you must have had a misscount when you originally made it
String[][] cellPhoneNumbers = new String[5][2];

//put in constructor or another appropriately named method
public GraphNumbers()
{
cellPhoneNumbers[0][0] = "Chile";
cellPhoneNumbers[0][1] = "21";
cellPhoneNumbers[1][0] = "Sweden";
cellPhoneNumbers[1][1] = "11";
cellPhoneNumbers[2][0] = "Peru";
cellPhoneNumbers[2][1] = "33";
cellPhoneNumbers[3][0] = "Bulgaria";
cellPhoneNumbers[3][1] = "10";
cellPhoneNumbers[4][0] = "Guatemala";
cellPhoneNumbers[4][1] = "18";
}
}

关于java - 错误信息找不到符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24689389/

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