Skip to content

Instantly share code, notes, and snippets.

@shaobin0604
Created March 17, 2010 13:34
Show Gist options
  • Select an option

  • Save shaobin0604/335222 to your computer and use it in GitHub Desktop.

Select an option

Save shaobin0604/335222 to your computer and use it in GitHub Desktop.
素数测试
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