I'm going to assume that this gripping drama takes place on planet Earth, where the acceleration of gravity is 9.8 m/s². The solutions would be completely different if the same scenario were to play out in other places.
A ball is thrown upward with a speed of 40 m/s. Gravity decreases its upward speed (increases its downward speed) by 9.8 m/s every second.
So, the ball reaches its highest point after (40 m/s)/(9.8 m/s²) = 4.08 seconds. At that point, it runs out of upward gas, and begins falling.
Just like so many other aspects of life, the downward fall is an exact "mirror image" of the upward trip. After another 4.08 seconds, the ball has returned to the height of the hand which flung it. In total, the ball is in the air for 8.16 seconds up and down.