Josimar Lee
Josimar Lee

Reputation: 11

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

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);
    }
}

Upvotes: 1

Views: 1871

Answers (1)

Edd
Edd

Reputation: 1370

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

Upvotes: 2

Related Questions