Last active
June 7, 2016 07:49
-
-
Save rahman99/dfcd611f75857fb803f1e9898fb6df54 to your computer and use it in GitHub Desktop.
Prime Number
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
| private static boolean isPrime(int number){ | |
| if(number<=1) | |
| return false; | |
| for(int i=2;i<Math.sqrt(number);i++){ | |
| if(number % i ==0) | |
| return false; | |
| } | |
| return true; | |
| } |
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
| private static void primeN(int n){ | |
| int count=2, status=1, num=3; | |
| if(n>=1) | |
| System.out.print(2+" "); | |
| while(count<=n){ | |
| for(int j=2;j<=Math.sqrt(num);j++){ | |
| if(num%j==0){ | |
| status = 0; | |
| break; | |
| } | |
| } | |
| if(status != 0){ | |
| System.out.print(num+" "); | |
| count++; | |
| } | |
| status =1; | |
| num++; | |
| } | |
| } |
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
| private static void prime(int beforeNumber){ | |
| String prime=""; | |
| int num=0; | |
| for(int i=1;i<=beforeNumber;i++){ | |
| int count=0; | |
| for(num =i; num>=1; num--) { | |
| if(i%num==0) | |
| count = count + 1; | |
| } | |
| if(count==2){ | |
| prime += i+" "; | |
| } | |
| } | |
| System.out.print(prime); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment