打印出100以内的质数,一行显示5个,(质数是只能被1跟自身整除的数,1不是质数)
public class PrimeNumNew {
public static void main(String[] args) {
// TODO Auto-generated method stub
int count =0;
for (int j = 2; j <= 100; j++) {
if(PrimeNum(j) == 1) {
count=count+1;
if(count%6==0){
System.out.println();}
else
System.out.print(j+” “);
}
}
}
static int PrimeNum(int num) {
for (int i = 2; i < num; i++) {
if (num % i == 0) {
return 0;
}
}
return 1;
}
}