未找到类定义错误
我在 NetBeans 中编写了以下类并成功运行。但是当我将它上传到 IEEE moshack 服务器时,我在那里参加了 IEEE Extreme 竞赛。
它说我的程序出现运行时错误。你能告诉我为什么吗?
import java.util.Scanner;
public class BloomFilter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] a = new int[26];
for (int b : a) {
b = 0;
}
String s = sc.nextLine();
String s1 = sc.nextLine();
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) >= 65 && s.charAt(i) <= 90) {
int p = s.charAt(i) - 65;
a[p] = 1;
}
if ((s.charAt(i) >= 97 && s.charAt(i) <= 122)) {
int p = s.charAt(i) - 97;
a[p] = 1;
}
}
String[] tokens = s1.split("[^a-zA-Z]");
int totWords = 0;
for (String s2 : tokens) {
s2.toLowerCase();
totWords++;
for (int j = 0; j < s2.length(); j++) {
if (a[s2.charAt(j) - 97] == 0) {
totWords--;
break;
}
}
}
System.out.print(totWords);
}
}
I wrote the following class in NetBeans and ran it successfully. But when I uploaded it to the IEEE moshack server where I participated for the IEEE Extreme competition.
It says that my program gives a run-time error. Can you please tell me why?
import java.util.Scanner;
public class BloomFilter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] a = new int[26];
for (int b : a) {
b = 0;
}
String s = sc.nextLine();
String s1 = sc.nextLine();
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) >= 65 && s.charAt(i) <= 90) {
int p = s.charAt(i) - 65;
a[p] = 1;
}
if ((s.charAt(i) >= 97 && s.charAt(i) <= 122)) {
int p = s.charAt(i) - 97;
a[p] = 1;
}
}
String[] tokens = s1.split("[^a-zA-Z]");
int totWords = 0;
for (String s2 : tokens) {
s2.toLowerCase();
totWords++;
for (int j = 0; j < s2.length(); j++) {
if (a[s2.charAt(j) - 97] == 0) {
totWords--;
break;
}
}
}
System.out.print(totWords);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
例如,旧版本的 DomJudge 要求 Java 类命名为
Main
;在这方面,较新的版本更好,但您上传它的地方可能存在类似的限制。检查 Java 期望的类名的错误消息,并尝试重命名您的类(当然还有文件)。
编辑:显然您尝试使用
java BloomFilter.class
而不是java BloomFilter
运行它。不过,我怀疑这是提交系统的问题(通常会更早发现这种情况),所以也许在某个地方您可以发出运行命令。Older versions of DomJudge for example required that Java classes are named
Main
; more recent versions are better in that regard, but maybe a similar restriction is in place where you uploaded it.Check the error message for the class name Java expected and try renaming your class (and the file, of course).
EDIT: Apparently you tried running it with
java BloomFilter.class
instead ofjava BloomFilter
. I doubt this is a problem with the submission system, though (such things are spotted earlier, generally), so maybe there is a place somewhere where you give the command to run.