一个方法中两个参数列表和整数,列表相邻相差绝对值与比较输入false和true
直接计算不使用绝对值的函数
- //has_close_elements([1.0, 2.0, 3.0], 0.5) False
- //has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3) True
- public static boolean listF(List<Integer> math, int c) {
- System.out.println(math.size()+",比较值:"+c);
- List<Boolean> bl=new LinkedList<>();
-
- int abdx0 = 0;
- for (int i = 0; i < math.size() - 1; i++) {
- int a = math.get(i);
- int b = math.get(i + 1);
-
- if (a - b > 0) {
- abdx0 = a - b;
- if (abdx0 > c) {
- bl.add(true);
- System.out.println("第"+i+"次,"+a+","+b+"相减D0:" + abdx0+",结果"+bl);
- } else {
- bl.add(false);
- System.out.p