为什么日食会在我写**的行中向我显示错误

问题描述 投票:0回答:3

所以为什么public static void main(String [] args)我遇到了错误。我该怎么解决]]

package linkedList;

public class HackerRank {

    public class Solution {

        // Complete the aVeryBigSum function below.
        public long aVeryBigSum(long[] ar) {
            long a=0;
            for(int i=0;i<ar.length;i++){
                a=ar[i]+a;
            }

            return a;
        }


        public static void main(String[] args) { ///why this line is not correct 
            Solution s= new Solution();
            long[] ar= {10000,20000,30000};

            System.out.println(s.aVeryBigSum(ar));

        }
    }
}

所以为什么要使用public static void main(String [] args),但出现错误。我该怎么做才能解决这个问题公共类HackerRank {公共类解决方案{//完成...

java eclipse methods static public
3个回答
1
投票

还有另一种可能的解决方案,将嵌套的Solution类从HackerRank类中移除,因为我看到您目前不对其进行任何操作。


0
投票

您不能在非静态类中访问静态方法。有两种可能的解决方案:-1.将解决方案设为静态


0
投票

删除外部类声明,public class HackerRankstatic方法只能在顶级类型内。

© www.soinside.com 2019 - 2024. All rights reserved.