fork download
  1. class GeneratePrimeNumbersExample {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. //define limit
  6. int limit = 100;
  7.  
  8. System.out.println("Prime numbers between 1 and " + limit);
  9.  
  10. //loop through the numbers one by one
  11. for(int i=1; i < 100; i++){
  12.  
  13. boolean isPrime = true;
  14.  
  15. //check to see if the number is prime
  16. for(int j=2; j < i ; j++){
  17.  
  18. if(i % j == 0){
  19. isPrime = false;
  20. break;
  21. }
  22. }
  23. // print the number
  24. if(isPrime)
  25. System.out.print(i + " ");
  26. }
  27. }
  28. }
Success #stdin #stdout 0.03s 246656KB
stdin
Standard input is empty
stdout
Prime numbers between 1 and 100
1 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