Created
March 17, 2010 13:34
-
-
Save shaobin0604/335222 to your computer and use it in GitHub Desktop.
素数测试
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
| public class Test { | |
| public static void main(String[] args) { | |
| int number = 37; | |
| if(isPrime(number)) | |
| System.out.println(number + " is a prime number"); | |
| else | |
| System.out.println(number + " is not a prime number"); | |
| } | |
| public static boolean isPrime(int number) { | |
| int temp = 2; | |
| boolean flag = true; | |
| //System.out.println(Math.sqrt(number)); | |
| while(temp < Math.sqrt(number)) { | |
| if(number % temp ==0) { | |
| flag = false; | |
| break; | |
| } | |
| temp++; | |
| } | |
| return flag; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment