100%(8)8 out of 8 people found this document helpful
This preview shows page 3 - 6 out of 7 pages.
ChkShCorrectfalse
3)What does userText.indexOf(',')return?84)What is the index of the lastcharacter in userText?135)What character doesuserText.charAt(userText.length()- 1) return?46)What doesuserText.substring(0, 3) return?Mar7)What doesuserText.substring(userText.length()- 4, userText.length()) return?2034A common error is to access an invalid array index, especially exactly one larger than the largestindex. Given userText with size 8, the range of valid indices are 0..7; accessing with index 8 is anerror.CheckShow answerThe string is not empty. Same as userText.length()== 0.CheckShow answerCorrect8',' is the 9th character, so its index is 8.CheckShow answerCorrect13There are 14 characters, so the index of the lastcharacter is 13.CheckShow answerCorrect4That's one way to get the last character.CheckShow answerCorrectMarString starting with M and ending with r.CheckShow answerCorrect2034That form gets the last 4 characters.Feedback?
PARTICIPATIONACTIVITY6.8.3: String access.The charAt(index) method generates an exception if the index is out of range for the string'ssize. An exceptionis a detected runtime error that commonly prints an error message andterminates the program.PARTICIPATIONACTIVITY6.8.4: Out-of-range string access.Given userText = "Monday".1) userText.charAt(userText.length())yields 'y'.CHALLENGEACTIVITY6.8.1: Looking for characters.Write an expression to detect that the ±rst character of userInput matches ±rstLetter. System.out.print(name.charAt(0)); System.out.print(name.charAt(1)); System.out.print(name.charAt(2)); System.out.println(name.charAt(3));75767778...Amynamek79012otherVarAm yout of rangeEXCEPTIONFeedback?