Answer:
Fill the 5 gallon container and empty it into the
3 gallon
contains so the latter is just full. Now
there is 2 gallons left in the 5 gallon container.
Empty the 3 gallon container and spill the 2
gallons into the 3 gallon container.
Fill the 5 gallon container and empty it so it just fills the 3
gallon
container (you need one gallon to do this).
Now there are 4 gallons left in the 5 gallon container.
Another solution as pointed out by a Dr. Solina is to take the 3 gallon and fill it. Empty it into the 5 gallon. Now use the 3 gallon container again to fill the 5 gallon all the way. What remains in the 3 gallon container is one gallon. Now, empty the 5 gallon container and pour the one gallon into it. Just add the contents of a 3 gallon container into it to make 4 gallons.