Java ArrayIndexOutOfBoundsException error when correct code is put together<>
This question already has an answer here:
This line seems to be throwing the exception:
So myWords must not have a second element, meaning the string Sentence didn't contain a space (" ") to be split on. Since Sentence is coming from sc.nextLine(), the "problem" must be with your input - but the true issue is that you're not handling that case properly.
Just glancing at your logic, I don't see why shortestLengths couldn't start out as Integer.MAX_VALUE since you're looping over each word and seeing if its length is less than that.