7.) Level 3 Given the following code in main: String[] names…
7.) Level 3 Given the following code in main: String[] names = {“Mary”, “John”, “Jill”, “MARY”, “Joe”, “MaRy”, “Chris”};String searchName = “Mary”;int count = searchArray(names, searchName);sout(“There are ” + count + ” occurrences of ” + searchName + ” found in the array.”); Write the code for the method called searchArray which: 1.) Receives 2 parameters: a.) A String array called names b.) A String called searchName 2.) Returns the number of times that the searchName occurred in the array, without regard to the case of the String in searchName.
Read Details15.) Level 1 Given the following code snippet: String[] ani…
15.) Level 1 Given the following code snippet: String[] animals = {“cat”, “elephant”, “dog”, “giraffe”, “zebra”};String selectedAnimal = animals[0];int maxLength = animals[0].length(); for (String anAnimal : animals) { if (anAnimal.length() > maxLength) { maxLength = anAnimal.length(); selectedAnimal = anAnimal; }} System.out.println(selectedAnimal + ” ” + maxLength); What is the output of this code?
Read Details18.) Level 2 Given the following code snippet: String[] par…
18.) Level 2 Given the following code snippet: String[] participants = {“Alice”, “Bob”, “Charlie”, “Diana”, “Ethan”, “Fiona”}; Scanner scanner = new Scanner(System.in);System.out.println(“Enter location: “);int location = scanner.nextInt();String result = “”; for (int i = 0; i < participants.length; i++) { result += participants[i].charAt(location);} System.out.println(result); When the program ran the user entered the following in the console: Enter location: 3 What is the output of this code?
Read Details