Question: Write a Java program that reads a string str and a word wrd ( another string but with no spaces ) as inputs and determines

Write a Java program that reads a string str and a word wrd (another string but with no spaces)
as inputs and determines how many times wrd appears in the string str.
Programming requirements
You should read both str and wrd from the input in the main method. Make sure that you use
two separate lines to give the input and use scan.nextLine().
You should write a non-void method named countWord that accepts two strings, sentence
and word, as parameters. It should return the number of times word occurs in sentence. For
example, if the string sentence is
My favorite subject is Computers but that subject is harder than Math
although it is a subject known for a long time.
and the word is "subject", then the method should return 3. Make sure to use the String
method equalIgnoreCase () so that the comparison of words is case insensitive.
Write a Java program that reads a string str and

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!