Cancer is one of the most the gravest problems facing mankind. In 2008, it is estimated that over 7.6 million lives have been claimed by cancer. Early and precise detection plays a key role in treating the disease and improve survivability of patient. Among data classification algorithms, discrete particle swarm optimization (DPSO), a technique based on standard PSO has proved to be competitive in predicting breast cancer, and in this paper, we implement a classifier using DPSO with new rule pruning procedure for detecting lung cancer and breast cancer, which are the most common cancer for men and women. Experiment shows the new pruning method further improves the classification accuracy, and the new approach is effective in making cancer prediction.