【发布时间】:2021-02-23 20:50:10
【问题描述】:
这是我目前所拥有的:
public class ArraySort {
//method to search the array for an int x
public int search(int x) {
int[] testArray = {};
for (int i = 0; i < testArray.length; ++i) {
if (testArray[i] == x) {
return (x);
} else if (testArray[i] != x) {
return -1;
} else {
return 1;
}
}
}
//main method
public static void main(String[] args) {
int[] testArray = {1, 2, 3};
int x = 3;
System.out.print(search(x));
}
}
【问题讨论】:
-
不要气馁。看起来搜索方法应该是
static和testArray应该是静态成员变量或传递给search方法。 -
@NomadMaker 抱歉
标签: java arrays sorting search