题解 | #查找组成一个偶数最接近的两个素数#
查找组成一个偶数最接近的两个素数
http://www.nowcoder.com/practice/f8538f9ae3f1484fb137789dec6eedb9
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int min=0;
int max=0;
int oushu = in.nextInt();
oushu=oushu/2;
for (int i = 0; i < oushu; i++) {
min=oushu-i;
max=oushu+i;
if(jiancha(max)==0&&jiancha(min)==0){
System.out.println(min);
System.out.println(max);
break;
}
}
}
}
public static int jiancha(int a) {
int k=0;
for (int i = 2; i < a ; i++) {
if (a % i == 0) {
k=-1;
break;
} else {
k= 0;
}
}
return k;
}
}