fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Prime {
  7. public static void main(String[] args) throws java.lang.Exception {
  8. // your code goes here
  9.  
  10. List<Integer> list = new ArrayList<>();
  11.  
  12. boolean[] isComposite = new boolean[100 + 1];
  13. isComposite[1] = true;
  14.  
  15. for (int i = 2; i <= 100; i++) {
  16. if (!isComposite[i]) {
  17. // 'i' is a prime number
  18. list.add(i);
  19. int multi = 2;
  20. while (i * multi <= 100) {
  21. isComposite[i * multi] = true;
  22. multi++;
  23. }
  24. }
  25. }
  26.  
  27. System.out.println(Arrays.toString(list.toArray()));
  28.  
  29. }
  30. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
[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]