私の宿題はクラスメソッドだけを求めていますが、.java と .class ファイルを提出する必要があります。理論的には動作するはずのコードがありますが、何を試してもコンパイルされません。たとえば、次のとおりです。
public class findFourLetterWord(String[] strings) {
public static void main(String[] args) {
for (int i = 0; i < strings.length; i++)
if (strings[i].length()==4)
return strings[i];
return null;
}
}
ここに私が得ているエラーがあります:
8 errors found:
File: D:\School\CSC 2310\hw5_elemmons1\FindFourLetterWord.java [line: 9]
Error: The public type findFourLetterWord must be defined in its own file
File: D:\School\CSC 2310\hw5_elemmons1\FindFourLetterWord.java [line: 9]
Error: Syntax error on token "(", { expected
File: D:\School\CSC 2310\hw5_elemmons1\FindFourLetterWord.java [line: 9]
Error: Syntax error on token ")", ; expected
File: D:\School\CSC 2310\hw5_elemmons1\FindFourLetterWord.java [line: 9]
Error: Syntax error, insert "}" to complete Block
File: D:\School\CSC 2310\hw5_elemmons1\FindFourLetterWord.java [line: 11]
Error: Cannot make a static reference to the non-static field strings
File: D:\School\CSC 2310\hw5_elemmons1\FindFourLetterWord.java [line: 12]
Error: Cannot make a static reference to the non-static field strings
File: D:\School\CSC 2310\hw5_elemmons1\FindFourLetterWord.java [line: 13]
Error: Cannot make a static reference to the non-static field strings
File: D:\School\CSC 2310\hw5_elemmons1\FindFourLetterWord.java [line: 14]
Error: Void methods cannot return a value
助言がありますか?