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(' ')); } }