Problem

In the following program skeleton, replace <Insert code here.> with your own code. H...

In the following program skeleton, replace <Insert code here.> with your own code. Hint: Use the variables that are already declared for you (songs, searchText, foundIndex, and count). The resulting program should prompt the user for a search string and then display the number of occurrences of the search string in a given list of songs. Study the sample session.

import java.util.Scanner;public class CountSubstringOccurrences{public static void main(String[] args){Scanner stdIn = new Scanner(System.in);String songs ="1. Green Day - American Idiot\n" +"2. Jesus Jones - Right Here, Right Now\n" +"3. Indigo Girls - Closer to Fine\n" +"4. Peter Tosh - Equal Rights\n";String searchText; // text that is searched forint foundIndex; // position of where text is foundint count = 0; // number of occurrences of search textSystem.out.print("Enter search text: ");searchText = stdIn.nextLine();System.out.println("Number of occurrences of \"" +searchText + "\": " + count);} // end main} // end class CountSubstringOccurrences

Sample session:

Enter search text: RightNumber of occurrences of "Right": 3

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 5
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT