阵列常量只能在初始化错误使用 [英] Arrays constants can only be used in initializers error

查看:134
本文介绍了阵列常量只能在初始化错误使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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"},

我怎么能做出,所以我可以从不同的方法调用数组?

how can I make it so I can call the array from a different method?

推荐答案

比意味着你必须将其初始化像这样

Than means you have to initialize it like this

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){
     ...
}

如果你想使用数组初始化,你不能分割的声明和分配。

If you want to use the array initializer, you cannot split the declaration and assignment.

这篇关于阵列常量只能在初始化错误使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆