I have this code that is supposed to check if the character in a string which is '/' is at the index 4 or index 5 of the string "2/20/2020" if it is there it is true and else false. I did this for the first '/' in the string and it works perfectly fine but honestly I have no idea what is going on with the second one. If it works for the first '/' it should definitely work for the second '/'.
Indeed. Well done. What indexOf() does is it looks for the first occurrence of the forward slash. The inner if statement checks whether the first occurrence is at index 4 or index 5. Neither are correct hence the reason it returns false.
Using lastIndexOf() is a good solution. Another solution is to use an overloaded version of indexOf(), namely the one that takes two parameters. That one allows you to specify an index as of which the search must start.
Beginning programmer - self-taught
Oracle Certified Associate Java SE 8