gpt4 book ai didi

java - 数组常量只能用于初始化错误

转载 作者:搜寻专家 更新时间:2023-10-30 21:21:54 26 4
gpt4 key购买 nike

考虑:

public proj 3 {

static string [][]Item;

public static void main(String [] args){

Item[][] = {
{"BH," , "Backhoe," , "200.00"},
{"ER," , "Electric Rake," , "10.00"},
{"EL," , "Electric Lawnmower," , "15.00"},
{"TR," , "Trencher" , "35.00"},
{"MU," , "Mulcher," , "20.00"},
{"TS," , "Tree Sprayer," , "22.00"},
{"CP," , "Cider Press," , "30.00"},
{"PR," , "Pruner," , "12.00"},
{"GE," , "Gas Edger," , "20.00"},
{"RO," , "Roller," , "8.00"},

我怎样才能做到这一点,以便我可以从不同的方法调用数组?

最佳答案

这意味着你必须像这样初始化它:

public class Proj3{

public static String [][] Item = {
{"BH," , "Backhoe," , "200.00"},
{"ER," , "Electric Rake," , "10.00"},
{"EL," , "Electric Lawnmower," , "15.00"},
{"TR," , "Trencher" , "35.00"},
{"MU," , "Mulcher," , "20.00"},
{"TS," , "Tree Sprayer," , "22.00"},
{"CP," , "Cider Press," , "30.00"},
{"PR," , "Pruner," , "12.00"},
{"GE," , "Gas Edger," , "20.00"},
{"RO," , "Roller," , "8.00"}
};

public static void main(String [] args){
...
}

如果要使用数组初始值设定项,则不能拆分声明和赋值。

关于java - 数组常量只能用于初始化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6348479/

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