Archive for the ‘Data Structure’ Category

求自然数n以内的质数

今天遇到这样一道题目:求自然数n以内的质数 经过观察以后,我觉得可以以下方式来求解: 将已求解的质数放入结果数组,判断下一个数是否是质数,只要将它除以质数结果数组,如果都不能被整除,那么这个数也是一个质数,放入结果数组中。 /* * PrimeNumber.java * * Created on 2006年8月12日, 下午6:05 * * This class is under Gnu GPL. */ package primenumber; import java.io.IOException; /** * Get prime numbers. * * @author <a href=”guangquanzhang@gmail.com“>guangquanzhang</a> */ public class PrimeNumber { /** Creates a new instance of PrimeNumber */ public PrimeNumber() { } /** * @param [...]

By javafuns on April 24, 2007 at 00:15 · Views: 1,827 · Permalink · RSS · 3 Comments
Categorized in: Data Structure, Java · Tagged with: ,
  • Highest Rated

  • My PicasaPhotos

    IMG_0605.JPG

    IMG_0671.JPG

    IMG_0520.JPG

  • RSS My del.icio.us

  • My RSS