Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write some Java statements that use the String methods indexOf and substring to

ID: 3613611 • Letter: W

Question

Write some Java statements that use the String methods indexOf and substring to find the first word in thestring. We define word to be a string of characters that does notinclude whitespace. For example the first word of the string "Hello, my goodfriend!" is the string "Hello," andthe second word is the string "my". Write some Java statements that use the String methods indexOf and substring to find the first word in thestring. We define word to be a string of characters that does notinclude whitespace. For example the first word of the string "Hello, my goodfriend!" is the string "Hello," andthe second word is the string "my".

Explanation / Answer

publicString getFirstWord(String input) { if(input.indexOf('')>0) { return input.substring(0,input.indexOf(' ')); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote