How can I prevent moles from growing into cancer?

Watch closely. You should watch the moles to see if any is growing, changing color, bleeding or becoming a mass. If you see any changes, consult your doctor. If you want to be absolutely sure, you could have the mole in concern removed, however, that is usually not a practical issue since most people have multiple moles.
Surveillance, lotion. Periodic surveillance is important. If there is any change- either in size/color or become symptomatic- itchy, bleeding etc- seek medical attention-go to see your doctor or dermatologist. Avoid to get too much uv exposures- use sun block w/ high spf, long sleeve, hat etc- ( especially if you are at high risk- fair skin, blond hair etc, personal h/o melanoma or strong family history of melanoma).