我正在尝试基于一个简单的算法来获取数组的元素。在这个例子中,我得到了索引总和为二的元素(模块三)我写了这个方法,但是 jcreator 给了我“return statement is missing”。我该如何解决这个问题。
public class hw1 {
public static void main(String[] args) {
String[][] RaggedArray = {
{ "hello", "hi", "i", "nice", "good", "love" },
{ "what", "java", "there" },
{ "and", "cool", "door", "my" },
{ "time", "phone", "homework" }
};
System.out.println(hw_one(RaggedArray));
}
public static String hw_one(String[][] array) {
String result;
for (int row = 0; row < array.length; row++) {
for (int column = 0; column < array[row].length; column++) {
if ((row + column) % 3 == 2) {
result = array[row][column];
}
}
}
return result;
}
}