判断一个正整数是否为质数
2014-03-18 21:52
253 查看
import java.lang.Long;
import java.lang.Math;
public class Test
{
public static void main(String[] args){
System.out.println("input :"+args[0]);
System.out.println("判断是否为质数(是/否 1/0):"+
new Test().isPrime(Long.parseLong(args[0])));
}
public int isPrime(long a){
for(int i=2;i<a;i++){
if(a%i==0){
return 0;
}
}
return 1;
}
}
import java.lang.Math;
public class Test
{
public static void main(String[] args){
System.out.println("input :"+args[0]);
System.out.println("判断是否为质数(是/否 1/0):"+
new Test().isPrime(Long.parseLong(args[0])));
}
public int isPrime(long a){
for(int i=2;i<a;i++){
if(a%i==0){
return 0;
}
}
return 1;
}
}
相关文章推荐
- java做的一整形数据进制转换器
- 写给不想做OJ题的C++学习者
- Ehcache 中ehcache.xml 配置详解和示例
- Android APK 签名比对
- barcode EAN13 最后一位验证码
- TCP/IP协议栈概述及各层包头分析
- C#特性学习与使用(为枚举定义Description)
- JDBC应用程序的基本步骤
- poj分类
- C#学习之用Microsoft.office.interop.excel.dll导出excel
- 十五分钟介绍Redis数据结构
- HDU 2594 Simpsons’ Hidden Talents(KMP)
- c++中 子类父类的构造函数调用顺序
- 利用PHPMailer 来完成PHP的邮件发送
- 怎样处理MSER出现的嵌套区域
- php入门第八天
- 关于http直播的问题
- 利用PHPMailer 来完成PHP的邮件发送
- HDUOJ-----4510 小Q系列故事——为什么时光不能倒流
- 闲扯LUA之三