所以我的作业只要求我提供类方法,但它要求我提交一个 .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
有什么建议么?