import java.util.Arrays; import java.util.Scanner; public class demo3 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ int n = scanner.nextInt(); int q = scanner.nextInt(); int ints[] = new int[n]; for (int i = 0; i < n; i++) { ints[i] = scanner.nextInt(); } Arrays.sort(ints); while (q>0){ int min = Integer.MAX_VALUE; int res = 0; int s = scanner.nextInt(); for (int i = 0; i < n; i++) { int val = Math.abs(s-ints[i]); if(min>val){ min = val; res = ints[i]; }else{ break; } } q--; System.out.println(res); } } } } 为什么只过了测试用来