if语句检查变量是否在数组中?
If statement to check if a variable is in an array?
所以我用方法编写了以下程序:inputArray、selectionSort、binarySearch 和 printArray。我目前正在研究 main 方法,正在为要做什么而苦苦挣扎。
"Write the main method to invoke inputArray, selectionSort, and printArray methods. Next, your main method should ask the user to input a double value to use as a search key and then invoke the binarySearch method. Finally, the main method should print out the location of the key if it is in the list and an appropriate message if the key is not in the list."
如何打印二分查找的索引值?
需要使用二分查找法的return值:
if (binarySearch(array1, key) < 0) {
// key is not in the array
} else {
// key is in the array
}
所以我用方法编写了以下程序:inputArray、selectionSort、binarySearch 和 printArray。我目前正在研究 main 方法,正在为要做什么而苦苦挣扎。
"Write the main method to invoke inputArray, selectionSort, and printArray methods. Next, your main method should ask the user to input a double value to use as a search key and then invoke the binarySearch method. Finally, the main method should print out the location of the key if it is in the list and an appropriate message if the key is not in the list."
如何打印二分查找的索引值?
需要使用二分查找法的return值:
if (binarySearch(array1, key) < 0) {
// key is not in the array
} else {
// key is in the array
}