ACS-1903 Study Guide - Quiz Guide: Binary Search Algorithm, Array Data Structure, Newline

51 views2 pages

Document Summary

This program demonstrates the binary search method in the arraytools class. public class binarysearchdemo public static void main(string[] args) // the values in the following array are sorted. // in ascending order. int numbers[] = {101, 142, 147, 189, 199, 207, 222, 417, 429, 447, 521, 536, 600}; int result, searchvalue; System. out. print("enter a value to search for: "); searchvalue = keyboard. nextint(); // search for the value result = binarysearch(numbers, searchvalue); // display the results. if (result == -1) System. out. println(searchvalue + " was found at " + System. out. print("do you want to search again? (y or n): "); input = keyboard. nextline(); } while (input. charat(0) == "y" || input. charat(0) == "y"); The binarysearch method performs a binary search on an integer array. The array is searched for the number passed to value. If the number is found, its array subscript is returned. Otherwise, -1 is returned indicating the value was not found in the array.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents