At this time, he needs your guidance and help the most. You can tell him about the failures of some successful people in life, and tell him that failure is the mother of success. Let him take his time, don't be anxious, adjust his mentality, and let him become as confident as before. You can do it only if you work hard.
You can give him some positive gifts, some books written by successful people, or something he likes very much. If he likes to play basketball, you can give him a good basketball to arouse his desire to play, distract his attention, and gradually make him forget about the exam. The most important thing is your encouragement and support. Everyone has failures. Let him know that failure is a common thing in the military, and don't let him be too extreme. You can give him some personalized gifts to make him happy, such as customized certificates, T-shirts, or a pair of basketball shoes he really wants to get. You can give him anything you can think of. He will feel much more relieved knowing that you are his friend by his side.