為什么我這樣寫算不出素數呢 很不解
public class test2 {
public static void main(String[] args) {
int a = 20150918;
boolean sss=true;
for(int b=2;b<=a/2;b++){
if(a%b == 0){
sss = false;
break;
}
if(sss){
System.out.println("素數是"+a);
break;
}
else{
++a;
}
}
}
}
public class test2 {
public static void main(String[] args) {
int a = 20150918;
boolean sss=true;
for(int b=2;b<=a/2;b++){
if(a%b == 0){
sss = false;
break;
}
if(sss){
System.out.println("素數是"+a);
break;
}
else{
++a;
}
}
}
}
2015-10-11
舉報
2015-10-11
public class test2 {
public static void main(String[] args) {
int a;
int b;
for(a=2;a<=100;a++){
if (a <= 3) { ?
? ? ? ? ? ? ? ? System.out.println("素數是"+a); ?
? ? ? ? ? ? } else { ?
? ? ? ? ? ? for( b=2;b<=a/2;b++){
? ? ? ? ? ? if((a%b)==0)
? ? ? ? ? ? {
? ? ? ? ? ? break; ?
? ? ? ? ? ? }else{
? ? ? ? ? ? if(b>=a/2)System.out.println("素數是"+a);
? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? }
}
}
}