当前位置: 技术问答>java相关
急:请问如何实现函数中的数组返回?
来源: 互联网 发布时间:2015-11-07
本文导语: 要在以下2个方法中输入代码,关键是如何实现数组的返回,请指教!最好有完整的代码! import genesis.*; public class Marks { public static void main (String [ ] args) { int [ ] marks = {57, 91, 72, 84, 63, 45, 95, 66, 77, 89};...
要在以下2个方法中输入代码,关键是如何实现数组的返回,请指教!最好有完整的代码!
import genesis.*;
public class Marks {
public static void main (String [ ] args) {
int [ ] marks = {57, 91, 72, 84, 63, 45, 95, 66, 77, 89};
Transcript.println(numbersInRange(marks, 60, 80));
Transcript.println(nearestToTarget(93, marks));
}
public static int numbersInRange
(int [ ] intArray, int lower, int upper) {
// ...
// complete the code for this method
// ...
}
public static int nearestToTarget
(int target, int [ ] intArray) {
// ...
// complete the code for this method
// ...
}
}
import genesis.*;
public class Marks {
public static void main (String [ ] args) {
int [ ] marks = {57, 91, 72, 84, 63, 45, 95, 66, 77, 89};
Transcript.println(numbersInRange(marks, 60, 80));
Transcript.println(nearestToTarget(93, marks));
}
public static int numbersInRange
(int [ ] intArray, int lower, int upper) {
// ...
// complete the code for this method
// ...
}
public static int nearestToTarget
(int target, int [ ] intArray) {
// ...
// complete the code for this method
// ...
}
}
|
public static int[] numbersInRange
这么定义就好了
这么定义就好了
|
int[] i = function1(para1,para2);
|
能否不要修改方法的返回值类型?
那就把想要返回的數組寫到函數參數里
public static int numbersInRange(int [ ] intArray, int lower, int upper, int[] intDest)
{
...
//get intDest's value
return 0;
}
那就把想要返回的數組寫到函數參數里
public static int numbersInRange(int [ ] intArray, int lower, int upper, int[] intDest)
{
...
//get intDest's value
return 0;
}
|
接收指针啊~~~