Created
November 12, 2018 06:05
-
-
Save alifhasnain/7e0e0683c8ed2936c66bcdad82c3130f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
/** | |
* | |
* @author Niloy | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
int n; | |
Scanner input = new Scanner(System.in); | |
System.out.print("Enter the value : "); | |
n = input.nextInt(); | |
boolean[] array = new boolean[n+1]; | |
for(int i=0;i<n+1;i++) { | |
array[i] = true; | |
} | |
for(int i=2;i<(n+1)/2 ; i++) { | |
if(array[i]==true) { | |
for(int j=i+i;j<n+1;j+=i) { | |
array[j]=false; | |
} | |
} | |
} | |
for(int i=2;i<n+1;i++) { | |
if(array[i]==true) { | |
System.out.println(i + "\t"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment