Return 我可能会看到
Return 2D Array
我有一个创建二维数组的方法。我想 return 这个二维数组在另一个 class.
中使用它
public class drawBoxClass {
public String[] drawBox(int boxLength) {
String[][] arrayBox = new String[boxLength][boxLength+1];
//method stuff
return new String[][]arrayBox;
}
}
我已经尝试使用谷歌搜索如何 return 二维字符串数组,但我不知道如何 return 它。
我得到 "array dimension missing"。
您的代码有两个问题:
(1) Return 类型的 drawBox
方法签名应该是二维数组即 String[][]
,您当前的方法签名只能 return 一维数组
(2) return
语句应该像return arrayBox
(不需要再指定变量类型)
public String[][] drawBox(int boxLength) {
String[][] arrayBox = new String[boxLength][boxLength+1];
//method stuff
return arrayBox;
}
我有一个创建二维数组的方法。我想 return 这个二维数组在另一个 class.
中使用它public class drawBoxClass {
public String[] drawBox(int boxLength) {
String[][] arrayBox = new String[boxLength][boxLength+1];
//method stuff
return new String[][]arrayBox;
}
}
我已经尝试使用谷歌搜索如何 return 二维字符串数组,但我不知道如何 return 它。
我得到 "array dimension missing"。
您的代码有两个问题:
(1) Return 类型的 drawBox
方法签名应该是二维数组即 String[][]
,您当前的方法签名只能 return 一维数组
(2) return
语句应该像return arrayBox
(不需要再指定变量类型)
public String[][] drawBox(int boxLength) {
String[][] arrayBox = new String[boxLength][boxLength+1];
//method stuff
return arrayBox;
}