“The public type must be defined in its own file” but the file name and the class name is the same

半世苍凉 提交于 2020-01-05 08:55:21

问题


import java.util.StringTokenizer;

public class josimarleewords {

    private static String[] tokenize(String str) {
        StringTokenizer tokenizer = new StringTokenizer(str);
        String[] arr = new String[tokenizer.countTokens()];
        int i = 0;
        while (tokenizer.hasMoreTokens()) {
            arr[i++] = tokenizer.nextToken();
        }
        return arr;
    }

    public static void main(String[] args) {
        String[] strs = tokenize("He said, That's not a good idea.");
        for (String s : strs)
            System.out.println(s);
    }
}

回答1:


If your file is called Josimarleewords.java, then your class must be called Josimarleewords. Make sure you capitalize the first letter.



来源:https://stackoverflow.com/questions/43097029/the-public-type-must-be-defined-in-its-own-file-but-the-file-name-and-the-clas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!