Yes, but do you see what happens if the user enters a String without a period? Let's see what happens when you enter "hi" without the quotes.Since 'h' is not a period, the loop body is executed, placing 'h' into the array a.Since 'i' is not a period, the loop body is executed, placing 'i' into the array a.Since i is now outside the bounds of legal values for the String, you get a StringIndexOutOfBoundsException.Originally posted by eric elysia:
I am trying to write code that makes sure the user does enter a period.
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|