所谓素数就是只能被1和本身整除的数。这是我的代码:- class CalcNum
- {
- public static void main(String[] args)
- {
- calcNum(100);
- }
- public static void calcNum(int num)
- {
- int i=1;
- do
- {
- int j=2;
- do
- {
- if (j==i)
- System.out.println(i);
- else if (i%j==0)
- break;
- }
- while (++j<=i);
- }
- while (++i<=num);
- }
- }
复制代码 |
|