Eratosthenes sieve in Java


prime<<algorithm


import java.util.Scanner;
public class Sieve {
  public static void main(String[] args) {
    int n,i,j;
    Scanner key=new Scanner(System.in);
    System.out.print("n = ");
    n=key.nextInt();
    if(n<2) System.out.println("Brak liczb pierwszych w podanym zakresie");
    else{
      boolean[] del = new boolean[n+1];
      for(i=2;i<=n;i++) del[i]=false;
      i=1;
      do{
        i++;
        if(!del[i]){
          j=i*i;
          while(j<=n){
            del[j]=true;
            j+=i;
          }
        }
      } while(i*i<=n);
      for(i=2;i<=n;i++) if(!del[i]) System.out.printf("%10d",i);
    }
  }
}