@@ -0,0 +1,1353 @@
+/*%0A Printing all prime numbers from 1 to given n.%0A */%0Apackage PrimeNumbersAndFactorization;%0A%0Aimport java.util.Scanner;%0A%0Apublic class SieveOfEratosthenes %7B%0A        //--------------------------------------------------------------------------%0A    public static void main(String args%5B%5D)%7B%0A        Scanner scn =new Scanner(System.in);%0A        System.out.print(%22Enter a number : %22);%0A        int num=scn.nextInt();%0A        sieveOfEratosthenes(num);%0A    %7D%0A    //--------------------------------------------------------------------------%0A    private static void sieveOfEratosthenes(int num)%7B%0A        boolean prime%5B%5D=new boolean%5Bnum+1%5D;%0A        for(int i=0;i%3Cnum;i++)%0A            prime%5Bi%5D=true;%0A        %0A           for(int p = 2; p*p %3C=num; p++)%0A        %7B%0A            // If prime%5Bp%5D is not changed, then it is a prime%0A            if(prime%5Bp%5D == true)%0A            %7B%0A                // Update all multiples of p%0A                for(int i = p*2; i %3C= num; i += p)%0A                    prime%5Bi%5D = false;%0A            %7D%0A        %7D%0A         %0A        // Print all prime numbers%0A        for(int i = 2; i %3C= num; i++)%0A        %7B%0A            if(prime%5Bi%5D == true)%0A                System.out.print(i + %22 %22);%0A        %7D%0A    %7D%0A    //--------------------------------------------------------------------------%0A%7D%0A/*%0AOUTPUT%0AEnter a number : 50%0A2 3 5 7 11 13 17 19 23 29 31 37 41 43 47%0A*/

Algorithm to print prime between 1 to given n