未找到类定义错误

发布于 2024-12-11 23:15:26 字数 1246 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十年不长 2024-12-18 23:15:26

例如,旧版本的 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 of java 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文