写个返回集合的方法,里面放素数
你要是知道素数是什么,判断就行写个伪代码
  public class Test{
    list getSuShu(int a){
    if(a=素数)
     list.add(a);
   return list;
}  }
public class Zhu{
  Random  b = ....
     
       Test test = new Test();
       list c =  test.getSuShu(b);
  for(int i=0;i<test.length;i++){
     System.out.println(c.get(i));
}
}

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using System.Collections;namespace ConsoleApplication1
    {
        class bugPrimenumber  //求素数类
        {
            private int[] arrInt = new int[100];  //数组保存产生的随机数
            Random rd = new Random();   //产生随机数
            public void Bug()
            {            for (int i = 0; i < 100; i++)
                {
                    arrInt[i] = rd.Next(1, 1000);
                }
            }
            public void ifPrimenumber()  //判断是否是素数
            {
                string str = "";
                Console.WriteLine("请输入路径:如e:\\*.txt");
                string path = Console.ReadLine();
                for (int j = 0; j < arrInt.Length; j++)
                {
                    bool a = true;
                    for (int k = 2; k < arrInt[j]; k++)
                    {
                        if (arrInt[j] % k != 0)
                        {                    }
                        else
                        {
                            a = false;
                            break;
                        }
                    }
                    while (a)
                    {
                        str += arrInt[j].ToString() + "\r\n";  //把所有结果保存到一个字符串str里边
                        break;
                    }
                }
                //把str保存到文件中
                FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine(str);
                sw.Close();
                fs.Close();
                Console.WriteLine("文件保存成功,请到" + path + "查找相关文件");
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                bugPrimenumber b = new bugPrimenumber();
                b.Bug();
                b.ifPrimenumber();
            }
        }
    }
      

  2.   

    上述要求已经全部实现,自己copy到net2005去研究研究