DESKTOP-8DEPNOJ_20200831-郭时佐
问题
求孪生素数问题
解答
package nhxz;
public class Su {
public String apple() {
String s = "";
for (int x = 2; x < 1000; x++) {
if (this.appleTest(x) && this.appleTest(x + 2)) {
s += x + "和" + (x + 2) + ";";
}
}
return s;
}
public boolean appleTest(int x) {
for (int t = 2; t < x; t++) {
if (x % t == 0) {
return false;
}
}
return true;
}
public static void main(String[] args) {
Su a = new Su();
String x = a.apple();
System.out.println(x);
}
}
吐槽
同桌太厉害,努力追赶他!
近期评论