java输出1-100之间的全部素数
public class Test10 {public static void main(String[] args) {int i = 2;while (i <= 100) {int num = 2;boolean flag = true;while (num < i) {if (i % num == 0) {flag = false;}num++;}if (flag) {System.out.print(i+"\t");}i++;}}
}
执行代码如下: