使用while循环输出2-100的所有素数,每行输出5个
分析:素数:只能被1和自己整除的自然数
public static void main(String[] args) {int num = 2;int count = 0;int count1 = 0;while (num <= 100) {for (int i = 1; i <= num; i++) {if (num % i == 0) {count++;}}if (count == 2) {System.out.print(num+" ");count1++;if (count1 % 5 == 0) {System.out.println();}}count=0;num++;}