【程序27】
题目:求100之内的素数(1是不是素数?)
package com.gyy.exercise;
public class Exercise27 {
public static void main(String[] args) {
for(int i = 1; i <= 100; i++)
{
int j;
for(j = 2; j < i; j++)
{
if( i % j == 0)
break;
}
if(j == i)
System.out.println(i);
}
}
}
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
Process finished with exit code 0