Write a program that has these overloaded search methods to do array searching:
boolean search(int[] arr, int searchKey) – searches an integer array given a search key value, returns true if searchKey is found, false if not.
Hint:
boolean found=false;
for(int i=0; i<arr.length; i++){
if( ){//compare the array element with the search key value
//action taken if found
}
}
//return something
boolean search(String[] arr, String searchKey) – searches an array of strings given a search key value, returns true if searchKey is found, false if not.
(read Comparing_Strings.doc)
In the main method, you can declare and initialize the two arrays with random values, for example:
int[] intArray={7,3,2,8,1,0,9};
String strArray={"Enchanted","Bedazzled","Divine","Delighted","Elegant"};
Use the methods in the program.
Comments
Leave a comment