- public class Prime {
- /*
- *
- * 一般求素数方法
- *
- * @param args
- */
- public static void main(String[] args) {
- for (int i = 2; i < 100; i++) {
- int j;
- for (j = 2; j < (int) (Math.sqrt(i) + 1); j++) {
- if (i % j == 0) {
- break;
- }
- }
- if (j > (int) Math.sqrt(i)) {
- System.out.print(i + " ");
- }
- }
- }}
- 1. public class Prime {
- 2. /*
- 3. *
- 4. * 一般求素数方法
- 5. *
- 6. * @param args
- 7. */
- 8.
- 9. public static void main(String args[])
- 10. {
- 11. int i,j;
- 12. for(j=2;j<=100;j++) //2-100的数
- 13. {
- 14. for(i=2;i<=j/2;i++) //
- 15. {
- 16. if(j%i==0)
- 17. break;
- 18. }
- 19. if(i>j/2) //
- 20. {
- 21. System.out.print(" "+j);
- 22. }
- 23. }
- 24. }
- 25.
- 26.
- 27.
- 28. }