Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 12 Weeks Ago, 6 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Linear Search
Write a Java program, called SearchArray that contains a static method called countStrings() that accepts a 2D array of Strings and a String as its parameters. The method should return an integer value that is the total number of times the String being searched for is contained in the 2D String array. The array and search value should be taken in using user input in the main method. You should print an appropriate message to the screen if the element is found and how many times it exists in the array. Note: The countStrings() method should work irrespective of case.
Input
nÂ
mij mij+1 mij+2 .... mij+n
mi+1j mi+1j+1 mi+1j+2 .... mi+1j+nÂ
mi+nj mi+nj+1 mi+nj+2 .... mi+nj+n
xÂ
where n is the size of the square array, mi is an element in the array and x is the element that is being searched for.Â
Sample input 1
3
cat dog dUck
rabbit hen duCk
dUcK DucK goose
Duck
Sample input 2
4
Volvo Fiat Suzuki Toyota
fiat Suzuki Volvo Ferrari
Ferrari Porsche Lamborghini Jag
Jag Fiat Citroen Toyota
Opel
Output
A message stating if the element is found.
Sample output 1
 Duck is contained 4 times in the array
Sample output 2
 Opel was NOT found in the array