fork(12) download
  1. /**
  2.  * Author:- nikhil.lohia
  3.  */
  4. class Ideone {
  5.  
  6. public Ideone() {
  7. }
  8.  
  9. public static void main(String[] args) {
  10. Ideone method3 = new Ideone();
  11. // Code obtained from http://w...content-available-to-author-only...s.com
  12. // Feel free to copy but please acknowledge wherever possible
  13. method3.findPrimes(25);
  14. }
  15.  
  16. private void findPrimes(int limit) {
  17. int[] primes = new int[100];
  18.  
  19. // Special handling for the integer '2'
  20. primes[0] = 2;
  21.  
  22. // Number of primes encountered
  23. int primeCount = 1;
  24.  
  25. // Looping from 3, to the limit
  26. for (int i = 3; i < limit; i++) {
  27. boolean isPrime = true;
  28.  
  29. if (i % 2 == 0) {
  30. continue;
  31. }
  32.  
  33. for (int j = 0; j < primeCount; j++) {
  34. if (i % primes[j] == 0) {
  35. isPrime = false;
  36. }
  37. }
  38.  
  39. // Store the prime number and increment the count
  40. if (isPrime) {
  41. primes[primeCount++] = i;
  42. }
  43. }
  44.  
  45. // Print the primes
  46. for (int x : primes)
  47. if (x != 0)
  48. System.out.print(x + ",");
  49. }
  50.  
  51. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
2,3,5,7,11,13,17,19,23,