/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mypkg;import java.math.*;/**
 *
 * @author XiaoG
 */
public class Main {    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int count = 0;
        for (int i = 2; count <= 100; i++) {
            if (isPrime(i)) {
                count++;
                if ((count % 10)!=0) {
                    System.out.println(i + "  ");
                } else {
                    System.out.println('\n' + i + "  ");
                }
            }
        }
    }    public static boolean isPrime(int num) {
        for (int i = 2; i <= Math.sqrt(num); i++) {
            if ((num % i)==0) {
                return false;
            }
        }
        return true;
    }
}
请问,我这段代码在netbeans怎么不能正常运行啊?

解决方案 »

  1.   

    我非常奇怪,在debug中可以运行输出,但是一直换行……直接运行,就什么都没有了……
      

  2.   

    应该是你环境的问题,我的eclipse也能运行.
    你的出错吗?把错误也贴出来吧
      

  3.   

    Netbeans的运行结果
    2  
    3  
    5  
    7  
    11  
    13  
    17  
    19  
    23  
    39  
    31  
    37  
    41  
    43  
    47  
    53  
    59  
    61  
    67  
    81  
    73  
    79  
    83  
    89  
    97  
    101  
    103  
    107  
    109  
    123  
    127  
    131  
    137  
    139  
    149  
    151  
    157  
    163  
    167  
    183  
    179  
    181  
    191  
    193  
    197  
    199  
    211  
    223  
    227  
    239  
    233  
    239  
    241  
    251  
    257  
    263  
    269  
    271  
    277  
    291  
    283  
    293  
    307  
    311  
    313  
    317  
    331  
    337  
    347  
    359  
    353  
    359  
    367  
    373  
    379  
    383  
    389  
    397  
    401  
    419  
    419  
    421  
    431  
    433  
    439  
    443  
    449  
    457  
    461  
    473  
    467  
    479  
    487  
    491  
    499  
    503  
    509  
    521  
    523  
    551  
    547  
      

  4.   

    和五楼的结果一样,估计是你运行的过程有错吧
    你应该先编译,然后将编译后的文件放入包中,再在命令提示符中运行是应该是 Java 包名.javaname(Main)