贝壳:计算绝对值(暴力破解)
1. 题目
2. 代码
public class C6 { private static int N;//正整数个数 public static void main(String[] args) { Scanner sc = new Scanner(System.in); N = sc.nextInt(); sc.nextLine(); long [] val = new long[N];//正整数 String[] str = sc.nextLine().split(" "); for (int i = 0; i < N; i++) { val[i] = Long.valueOf(str[i]); } int position = 0; long min = Long.MAX_VALUE; for (int i = 0; i < N-1; i++) { long jueduizhi = Math.abs(val[i]-val[i+1]); if(min > jueduizhi){ min = jueduizhi; position = i; } } System.out.print(val[position]+" "+ val[position+1]); } }