Did Prophet Muhammad Exercise?
Question

I want to do some kind of exercise to increase my physical strength, but I want to do that in an Islamic manner. Did the Prophet (blessings and peace of Allah be upon him) do this kind of exercise? What is the style of swimming that the Messenger (blessings and peace of Allah be upon him) and his Companions (may Allah be pleased with them) used to do?
Praise be to Allah.The strong believer is better and more beloved to Allah 
Muslim (2664) narrated that Abu Hurayrah (may Allah be pleased with him) said: The Messenger of Allah (blessings and peace of Allah be upon him) said: “The strong believer is better and more beloved to Allah than the weak believer, although both are good.”
This strength includes both physical strength and strength of faith, as we have explained in the answer to question no. 10238 .
Allah, may He be Exalted, says (interpretation of the meaning):
“And their prophet said to them, `Indeed, Allah has sent to you Saul as a king.’ They said, `How can he have kingship over us while we are more worthy of kingship than him and he has not been given any measure of wealth?’ He said, `Indeed, Allah has chosen him over you and has increased him abundantly in knowledge and stature. And Allah gives His sovereignty to whom He wills. And Allah is all-Encompassing [in favour] and Knowing.’” [Al-Baqarah 2:247]
“and has increased him abundantly in knowledge and stature” means: He has favoured him over you and given him more in terms of knowledge and stature; in other words, He has given him deep insight and physical strength by means of which he is qualified for his post as king, for if he has deep insight and the ability to implement the right decision, he will be able to fulfil this role in the best manner, but if he were lacking in either of these two qualities, he would not be able to do his job properly. If he were physically strong but lacked deep insight, then the king would be unsuccessful in running the kingdom’s affairs, because his strength would not be used in a wise manner. If he had deep insight but did not have the strength to implement any decisions he made, his insight would not benefit him because he would not be able to achieve anything." (Tafsir As-Sa`di, p. 107)
Having physical strength, health and soundness helps a person to worship Allah by praying, fasting, performing Hajj, striving in Jihad, and so on. Being physically weak and sick is an impediment in doing many acts of worship.
What are the guidelines of practising sport in Islam?
There are matters of Islamic etiquette that one should pay attention to when playing sports and doing exercises to strengthen the body:

Seeking reward with Allah, and doing these things to help one worship Him and support those who have been wronged.
These activities should not involve anything that is contrary to Islamic teachings, such as participants bowing to one another , striking the face, uncovering the `awrah, gambling, and so on.
It should not distract one from obeying and worshipping Allah, honouring one’s parents and other important priorities.
One should not spend great amounts of wealth on it, to the point of extravagance; rather one’s involvement in such activities should be based on moderation and within the framework of Islamic teachings.

Did Prophet Muhammad Exercise?
We do not know of anything in the Sunnah to indicate that the Prophet (blessings and peace of Allah be upon him) used to do this kind of exercise or play sports as known nowadays. For Allah, may He be Glorified and Exalted, perfected His blessings upon him in all his affairs, and granted him perfect physical strength and strength of faith.
What we know of such matters that is proven in the Sunnah is the following:

Firstly: The Prophet (blessings and peace of Allah be upon him) wrestled with Rukanah (may Allah be pleased with him) before he became Muslim.

Abu Dawud (4078) narrated that Rukanah (may Allah be pleased with him) wrestled with the Prophet (blessings and peace of Allah be upon him) and the Prophet (blessings and peace of Allah be upon him) threw him to the ground. (Classed as sound by Al-Albani in Al-Irwaa’ (5/329)

Secondly: he raced with his wife `Aishah (may Allah be pleased with her).

Abu Dawud (2578) and Ahmad (26277) narrated that `Aishah (may Allah be pleased with her) said: I went out with the Prophet (blessings and peace of Allah be upon him) on one of his journeys when I was still young and had not put on weight. He said to the people: “Go on ahead.” So they went on ahead, then he (blessings and peace of Allah be upon him) said to me, “Come, let me race with you.” So I raced with him, and I beat him, and he said nothing. Later, when I had put on some weight, and I had forgotten about it, I went out with him on one of his journeys, and he said to the people: “Go on ahead.” So they went on ahead, then he (blessings and peace of Allah be upon him) said to me, “Come, let me race with you.” So I raced with him, and he beat me, then he smiled and said: “This is in return for that.” (Classed as authentic by Al-Albani in Saheeh Abu Dawud)

Thirdly: archery. Al-Bukhari narrated (3373) that Salamah ibn Al-Akwa` (may Allah be pleased with him) said: The Prophet (blessings and peace of Allah be upon him) passed by a group of Aslam who were competing in shooting arrows. The Messenger of Allah (blessings and peace of Allah be upon him) said: “Shoot, O sons of Isma`il, for your father was an archer. Shoot, and I am with the tribe of So-and-so.” One of the two groups stopped shooting, so the Messenger of Allah (blessings and peace of Allah be upon him) said: “What is the matter with you, why are you not shooting?” They said: O Messenger of Allah, how could we shoot when you are with them? He said: “Shoot, for I am with all of you.”

Did the Companions exercise?
Undoubtedly the Companions (may Allah be pleased with them) used to train in horsemanship and the skills of fighting and running, and they were extremely strong and tough.
Such matters vary from one time to another, and from one situation to another.
With regard to swimming , it is soundly narrated from the Prophet (blessings and peace of Allah be upon him) that he said: “Everything in which there is no remembrance of Allah is idle play, except four things: a man playing with his wife; a man training his horse; a man running between two lines (as in a race); and a man learning how to swim .” (Narrated by An-Nasa’i in As-Sunan Al-Kubra (8889); classed as authentic by Al-Albani in As-Sahihah (315)
We do not know of any report from the Prophet (blessings and peace of Allah be upon him) about swimming which suggests that he did it himself.
With regard to the words, “Teach your children to swim, shoot arrows and ride horses,” we do not know of any report with this wording from the Prophet (blessings and peace of Allah be upon him).
A similar phrase was narrated from him, “Teach your sons to swim and shoot arrows, and teach girls to spin.” But this is a very inauthentic Hadith. (See: As-Silsilat Ad-Da`ifah by Shaykh Al-Albani (3876, 3877))
For more details, please see the following answers: 
Is Boxing Haram?
Is Bodybuilding Haram?
And Allah knows best.