Last active
September 30, 2015 15:02
-
-
Save vajahath/110850ff955608c35cc1 to your computer and use it in GitHub Desktop.
Java Program to FILTER PRIMES
This file contains hidden or 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
//to filter primes | |
import java.io.*; | |
import java.util.*; | |
class FilterPrime | |
{ | |
int n; | |
FilterPrime(Scanner scan) | |
{ | |
System.out.print("Enter Limit Here:"); | |
n=scan.nextInt(); | |
} | |
int Process() | |
{ | |
int flag, count=0; | |
for(int i=3;i<=n;i++) | |
{ | |
flag=0; | |
for(int j=2;j<=(i/2)+1;j++) | |
{ | |
if(i%j==0) | |
{ | |
flag++; | |
break; | |
} | |
} | |
if (flag==0) | |
{ | |
System.out.print("\t"+i); | |
count++; | |
} | |
} | |
return count; | |
} | |
} | |
class Prime | |
{ | |
public static void main(String []args) | |
{ | |
Scanner scan=new Scanner(System.in); | |
FilterPrime obj=new FilterPrime(scan); | |
System.out.print("\n\n Primes in the limit "+obj.n+"are shown below:\n"); | |
int c=obj.Process(); | |
System.out.println("\n\n-------------\nTotal Count="+c); | |
} | |
} | |
//end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment