预期在大括号正确匹配时为'{‘。

huangapple go评论68阅读模式
英文:

expected '{' when braces are matching correctly

问题

以下是您要求的翻译内容:

嗨,我是(**非常)不熟悉Java,我有C++的背景,
我遇到了这个错误:

Array-Lists-In-java.java:3: 错误: 期望'{'
public class Array-Lists-In-java{
                  ^

这是我的代码:

import java.util.ArrayList;

public class Array-Lists-In-java {

    public static void main(String[] args)
    {
        ArrayList<String> grocery = {"Onions","Carrots","Olives", "olive oil"};
        
        printArray(grocery);
        
        grocery.add("Tomatoes");
        
        printArray(grocery);
        
    }
    
    public static void printArray(ArrayList<String> list)
    {
        for(int i = 0; i < list.size(); i++)
        {
            System.out.println(list.get(i));
        }
    }
    
}

我做错了什么?请纠正我错误的地方,这将非常有帮助

谢谢

英文:

Hi I am (very) new to java and I come from a c++ background
and I am getting this error:

Array-Lists-In-java.java:3: error: &#39;{&#39; expected
public class Array-Lists-In-java{
                  ^

and here is my code:

    import java.util.ArrayList;
    
    public class Array-Lists-In-java {
    
        public static void main(String[] args)
        {
            ArrayList&lt;String&gt; grocery = {&quot;Onions&quot;,&quot;Carrots&quot;,&quot;Olives&quot;, &quot;olive oil&quot;};
            
            printArray(grocery);
            
            grocery.add(&quot;Tomatoes&quot;);
            
            printArray(grocery);
            
        }
        
        public static void printArray(ArrayList&lt;String&gt; list)
        {
            for(int i = 0; i &lt; list.size(); i++)
            {
                System.out.println(list.get(i));
            }
        }
        
    }

what am I doing wrong??pls correct me where i am going wrong it would be really helpful

thanks

答案1

得分: 0

嘿,python_is_good_cpp_is_best!我认为你可能缺少或者多了一个花括号,记住每个花括号都应该有一个配对的伙伴!尝试一下数一下你有多少个开放的花括号,以及你有多少个闭合的花括号。如果它们数量相同的话,记得使用正确的命名约定。编程语言不支持名字中带有“-”,因为它们会认为你想要做减法运算。你的类名中有一个“-”,尝试用下划线“_”来替代“-”,应该会正常工作!谢谢你!

英文:

Hey python_is_good_cpp_is_best! I think you are missing or have an extra flower bracket somewhere, remember each flower bracket should have a buddy! Try counting how many open flower brackets you have, and how many closed flower brackets you have. if they are the same amount, remember to use proper naming convention, programming languages dont support names having '-' cause they think you want to do subtraction, you have a '-' in your class name, try replacing '-' with underscores '_' it should work properly! thankyou!

huangapple
  • 本文由 发表于 2020年9月25日 00:17:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/64050423.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定