先露一手,抛砖砸人
PS:我原来是C#,4年经验,为了做项目采用JAVA不久class PrimNum {
    int iVal;
    boolean isPr;
    
    PrimNum(int iNum)
    {
        int iNumd2 = (int)Math.sqrt((double)iNum);
        this.iVal = iNum;
        this.isPr = false;
        if (iNum < 0) {
            return;
        }
        
        for (int i = 2; i <= iNumd2; i++) {
            if (iNum % i == 0) {
                return;
            }
        }
        this.isPr = true;
    }
    
    public int getIntegerNum() {
        return this.iVal;
    }
    
    public boolean isPrim() {
        return this.isPr;
    }
}public class Test {
    Test() {
    }
    
    public void run() {
        System.out.println(new PrimNum(83).isPrim());
    }
    
    
    public static void main(String[] args) {
        new Test().run();
    }
}

解决方案 »

  1.   

    故意写麻烦的,JAVA也够麻烦了 再麻烦一点也不妨事 哈哈
      

  2.   


    还可以写的更复杂点嘛,搞个什匿名么内部类呀,什么的!        PrimNum(int iNum) {
            this.isPr = new Object() {            public boolean isPrimary(int checkNumber) {                return new Object() {                    public boolean checkIt(int checkNumber) {                        return new Object() {                            public boolean checkIt(int checkNumber) {
                                    PrimNum.this.iVal = checkNumber;
                                    if (checkNumber < 0)
                                        return false;                                for (int i = (int) Math.sqrt(checkNumber); i > 1; i--) {
                                        if (checkNumber % i == 0)
                                            return false;
                                    }
                                    return true;
                                }                        }.checkIt(checkNumber);
                        }                }.checkIt(checkNumber);
                }        }.isPrimary(iNum);
        }
      

  3.   

    牛B这一词早就过去,现在有的只是“软件码工”,难听点就是“码农”,就看你想当工人阶级还是农民阶级了
    http://blog.csdn.net/littlehedgehog/archive/2010/10/13/5939461.aspx
      

  4.   

    public class Test
    {
    private static boolean isSuShu(int number) {
    boolean flag = false;
    int count = 0;
    if (number == 1) {
    return false;
    } else {
    for (int i = 1; i <= number; i++) {
    if (number%i == 0) {
    count++;
    }
    if (count > 2) {
    break;
    }
    }
    if (count == 2) {
    flag = true; 
    }
    }

    return flag;
    } /**
     * @param args
     */
    public static void main(String[] args)
    {
    int test = 101;
    System.out.println(isSuShu(test));
    }}
      

  5.   

    for (int i = 3; i <= iNumd2; i+=2) { //前面判断以下1和2,然后这样循环
      

  6.   

    来个简洁点的:    PrimNum(int iNum) {
            for (int i = (this.isPr = (this.iVal = iNum) >= 0) ? 0 : (int) Math.sqrt(iNum); i > 1
                    && (this.isPr = (iNum % i == 00)); i--)
                ;
        }
      

  7.   

    当然要越复杂越好, 笨蛋呀,你想啊,你在一家公司如果你把代码写的那么好读,那么以后你还怎么硬起来,就是要写的只有TM自己认的,别的TM全部都不认得才行,笨啊 这还要楼主交你啊1!!!
      

  8.   

    跳大神没跳好,有BUG ,再跳呀,不要又跳错了 
        PrimNum(int iNum) {
            for (int i = (this.isPr = (this.iVal = iNum) >= 0) ? (int) Math.sqrt(iNum) : 0; i > 1
                    && (this.isPr = (iNum % i != 0)); i--)
                ;
        }
      

  9.   

    代码看着是有点繁琐 不过能在Linux上运行
    C#在linux上怎么运行呢?
      

  10.   


    public static void main(String[] args) {
            for (int i = 2; i < 100; i++) {
                int j;
                for (j = 2; j < (int) (Math.sqrt(i) + 1); j++) {
                    if (i % j == 0) {
                        break;
                    }
                }
                if (j > (int) Math.sqrt(i)) {
                    System.out.print(i + " ");
                }
            }
        }
      

  11.   

    this.isPr = (this.iVal = iNum) >= 0
    没看懂,求解释~
      

  12.   

    public static void main(String[] args) {
    for(int i=2;i<=100;i++){
     int j=2;
    while((i%j)!=0&&(i>j)){
    j++;
    if(j==i)
    System.out.print(" "+i);
      }
     }
    }
      

  13.   

    就是先把iNum赋值给iVal,并判断是不是大于非负,如果是负数直接就不干了