20s ele whose base is dateen, you m base) For example, a computer scientist e in
ID: 3605531 • Letter: 2
Question
20s ele whose base is dateen, you m base) For example, a computer scientist e integer x in binary. In that case, the total umser of bits required express a given positive rounded up to ow many bits the next higher integer. Write a Java statement that (1) calculates the number value and (2) assigns that calculated value into an int variable ot bits required to store variable x's assigns that CB. 1 fer §5.6] In the following program skeleton, replace withy your own code. Hint: Use ready declared for you (songs, searchText. found tndex, and coanti The ram should prompt the user for a search string and then display the number of occurrences of variables that are al import java.util.Scanner public class CountSubstringOccurrences public static void main(Stringll args) Scanner stdin- new Scanner (System.in) String songs "1. Green Day -American Idiotln"+ 2. Jesus Jones Right Here, Right Now 3. Indigo Girls -Closer to Fineln" + "4. Peter Tosh - Equal Rightsin" String searchText: // text that is searched for int foundIndex: I/ position of where text is found int t count - 01/ number of occurrences of search text System.out.print ("Enter search text: ") searchText = stdIn.nextLine(); cinsert code here.> System.out.println( Number of occurrences of " ) // end main searchText":"+count): ) / end class countSubstringoccurrences replace cInsert code here.>with your own code. Hint: Use um songIndex, eolIndex, and song er search text: Right of occurrences of "Right": 3Explanation / Answer
//Already declared, Make it 0 i.e foundIndex = 0 while(foundIndex != -1){ foundIndex = songs.indexOf(searchText,foundIndex); if(foundIndex!= -1){ count ++; foundIndex += searchText.length(); } }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.