[英]Why eclipse show me error in the line where i have written public static void main(String[] args)
So why public static void main(String[] args)
I got an error.那么为什么public static void main(String[] args)
我得到了一个错误。 what can i do to resolve it?我能做些什么来解决它?
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));
}
}
}
There is another possible solution, taking the nested Solution class out of the HackerRank class, as I see you are not doing anything with it at the moment.还有另一种可能的解决方案,将嵌套解决方案 class 从 HackerRank class 中取出,因为我看到您目前没有对它做任何事情。
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) {
Solution s = new Solution();
long[] ar = { 10000, 20000, 30000 };
System.out.println(s.aVeryBigSum(ar));
}
}
This makes sure that your static main method works.这确保您的 static 主要方法有效。
You can't access a static method in a non-static class. There are 2 possible solutions for this problem: - 1. Make Solution static您无法在非静态 class 中访问 static 方法。此问题有 2 种可能的解决方案:- 1. Make Solution static
public static class Solution {
public static void main(String[] args) {
//...
}
}
- 2. Remove the static from the main method - 2.从main方法中删除static
public class Solution {
public void main(String[] args) {
//...
}
}
So why public static void main(String[] args)
I got an error.那么为什么public static void main(String[] args)
我得到一个错误。 what can i do to resolve it?我能做些什么来解决它?
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));
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.