Skip to content
Snippets Groups Projects
Select Git revision
  • 9dda7b2f73f9ea08ecbfddc9d74c58c21a103783
  • master default protected
2 results

Primes.java

Blame
  • Forked from NAVES Guyslain / ProgAvExercices
    17 commits behind the upstream repository.
    user avatar
    Guyslain authored
    9dda7b2f
    History
    user avatar 9dda7b2f
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Primes.java 518 B
    package fr.univamu.progav.td1;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class Primes {
    
      public static List<Integer> primes(int max) {
        List<Integer> primes = new ArrayList<>();
        primes.add(2);
        for (int n = 3; n <= max; n = n + 2) {
          boolean isPossiblyPrime = true;
          for (int p : primes) {
            if (n % p == 0) {
              isPossiblyPrime = false;
              break;
            }
          }
          if (isPossiblyPrime) {
            primes.add(n);
          }
        }
        return primes;
      }
    
    }