老师说这样写不对,让我用定义质数的那种算法!
我想问下我这种方法对不对!大虾们帮看下!
public class PrimeNumber {
int number;
public void prime(){
if(number%2==0){
if(number==2){
System.out.print(number + "是质数!");
}
System.out.print(number + "不是质数!");
}else{
if(number<2){
System.out.print(number + "不是质数!");
}else{
if(number%3!=0&&number%5!=0&&number%7!=0||number==3||number==5||number==7){
System.out.print(number + "是质数!");
}else{
System.out.print(number + "不是质数!");
}
}
}
}
}
------解决方案--------------------
肯定不对啊...比如11 * 11 = 121 是不是质数。。。