java判断一个数是质数?

来源:百度知道 编辑:UC知道 时间:2024/06/04 06:29:26
不用boolean,用for怎么做啊???

public class aa {
static int a=2;
static void b(int n){

if(a==n/2+1)
System.out.println(n+"不是质数");
else if(n%a!=0)
{
a++;
b(a);
}
else System.out.println(n+"不是质数");
}
public static void main(String[] args){
int x=88;
if(x==1)
System.out.println(x+"不是质数");

else b(x);

}
}
没有for 用递归做的

不懂你说的什么意思??不用boolean??不判断??光用循环??那还真不知道怎么做..

.不用boolean是不可能做出来的..必须用boolean来判断到底能不能整除啊