{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ArrayBinarySearch

ArrayBinarySearch - import java.util.Scanner Fills an array...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.Scanner; i // Fills an array, and searches for a particular value / public class ArrayBinarySearch { public static void main(String[] args) { final int INTARRAY_LENGTH = 1000; int[] intArray = new int[INTARRAY_LENGTH]; int intArraySize = 0; Scanner in = new Scanner(System.in); //Call a method readData to fill the array; //returns the number of integers read intArraySize = readData(intArray); //print the array printArray( intArray, intArraySize); System.out.println( "What value are you searching for?" ); int searchNumber = in.nextInt(); //call the method to search in the array for the search number int position = binarySearch(intArray, intArraySize, searchNumber); System.out.println( searchNumber + " was found in the array in position " + position); p } /** Reads data from the console into an array @param data the array to be filled @return the number of the items read into the array */ public static int readData(int[] data) { Scanner in= new Scanner(System.in); boolean done = false; int dataSize = 0; while (!done ) { System.out.println("Enter an integer, -1 to quit:"); int number = in.nextInt();
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern