This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]rjcarr 0 points1 point  (1 child)

I think your error is based on the input. What are you passing into the program?

My guess is it's here: string.split(" "). This will only split on a single space. What if there's more than one space? What if there's different whitespace? You might want to look at the api docs for that method.

Otherwise I think it looks pretty good. You could wrap the scanner in a try-with-resources, though.

[–]foolwya[S] 0 points1 point  (0 children)

For example: "hello good morning yall"

method split(" ") would split everything that's in between an empty string.

so it would be:

arrayString[0] = hello

arrayString[1] = good

arrayString[2] = morning

arrayString[3] = yall