-1

Main.java:3:Holeintext 类是公共的,应在名为 Holeintext.java 的文件中声明 public class Holeintext { ^ 注意:Main.java 使用或覆盖了已弃用的 API。注意:使用 -Xlint:deprecation 重新编译以获取详细信息。1 个错误

这是错误我得到这是一个编译错误有人可以告诉我如何解决这个问题。请帮忙。在我的电脑上编译时,它运行时没有任何错误,但是当我将它上传到现场进行编译时,它会显示这个错误。

代码是:

package holeintext;
import java.io.*;
class Holeintext {
    public static void main(String[] args) throws Exception {
        // TODO code application logic here
        DataInputStream in = new DataInputStream(System.in);
        String s;
        char[] str;
        System.out.println("INPUT:");
        int c = Integer.parseInt( in .readLine());
        String[] str1 = new String[c];
        for (int m = 0; m < c; m++) {
            s = in .readLine();
            str1[m] = s; //at this point we have a array with our input
        }
        System.out.println("OUTPUT:");
        for (int g = 0; g < str1.length; g++) {
            s = str1[g];
            str = s.toCharArray();
            int i = 0;
            int count = 0;
            while (i < str.length) {
                if ((str[i] == 'A') || (str[i] == 'D') || (str[i] == 'O') ||
                    (str[i] == 'P') || (str[i] == 'R')) {
                    count = count + 1;
                } else
                if (str[i] == 'B') {
                    count = count + 2;
                }
                i++;
            }
            System.out.println(count);
        }
    }
}
4

2 回答 2

2

从错误中我可以猜到,您已经使用类名以外的其他名称保存了文件Holeintext

public class Holeintext {
 ...
 ....
}  

解决方案:

1.从类中删除公共访问说明符

class Holeintext{  
 ....  
 ...   
}

2.或保存文件Holeintext.java

有用的链接

于 2013-10-16T08:22:50.173 回答
2

在 java 中,公共类必须在具有相应名称的文件中。所以类Dog必须在文件中Dog.java。弃用不是编译器错误,但 classname-filename 是。

于 2013-10-16T08:18:23.873 回答