Arrays constants can only be used in initializers error

前端 未结 5 1874
谎友^
谎友^ 2020-11-30 10:19

Consider:

public proj 3 {

    static string [][]Item;

    public static void main(String [] args){

        Item[][] = {
             {\"BH,\" , \"Backhoe,         


        
5条回答
  •  执念已碎
    2020-11-30 11:07

    If your target is: 1. declare it somewhere; 2. initialize it somewhere else; 3. still want to use the {...} format. This will work:

    public proj 3 {
    
        static string [][]Item;
    
        public static void main(String [] args) {
    
            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"}
            };
            Item = _Item;
    

提交回复
热议问题