[英]how to fix a bad source file error in Java?
These are my codes:这些是我的代码:
public class Solution {
public boolean isBalanced(String s) {
Stack<Character> stack = new Stack<Character>();
char c;
for(int i = 0; i<s.length(); i++) {
c = s.charAt(i);
if(c == '[' || c == '(') {
stack.push(c);
}
else if(c == ']' || c == ')'){
if(stack.isEmpty()) {
return false;
}
else if(c == ']' && stack.peek() == '[') {
stack.pop();}
else if(c == ')' && stack.peek() == '(') {
stack.pop();
}
else {
return false;
}
if (stack.isEmpty()){
return true;
}
}
}
return false;
}
public static void main(String[] args) {
Solution solution = new Solution();
System.out.println(solution.isBalanced("()")); // should be true
System.out.println(solution.isBalanced("(")); // should be false
System.out.println(solution.isBalanced("(])")); // should be false
}
}
and I am getting this error:我收到了这个错误:
Solution.java:4: error: duplicate class: a22629.Solution
public class Solution {
^
MyTests.java:6: error: cannot access Solution
Solution solution;
^
bad source file: ./Solution.java
file does not contain class Solution
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
2 errors
Not compiled
This is the full error I am getting and I am not sure why.这是我得到的完整错误,我不知道为什么。
When I compile it in terminal it works, but when I want to submit it to my class portal, it does not work and gives me this error.当我在终端中编译它时它可以工作,但是当我想将它提交到我的 class 门户时,它不起作用并给我这个错误。
Please share more code Or add the command line data of your successful compilation and invocation.请分享更多代码或添加您成功编译和调用的命令行数据。
default
access scope for your class.default
访问权限 scope。 Ensure that your class is public
to be accessible to other's outside of your package.public
的,以便 package 之外的其他人可以访问。 (Though locally you can still compile and run the class independently, other classes outside of your package can not access your class)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.