Why is this code not validated if it is working?
It seems to me, in the task "Closest to 10" (level04.lecture04) there is an error in the verification condition:
1) if dysplayClosesToTen (7, 14); then the result will be 7.
2) if dysplayClosesToTen (-7, 14); then the result will be 14, and should be -7.
public static int abs (int -7) = 7, and 7 closer to 10 than 14.
package com.codegym.task.task04.task0409;
/*
Closest to 10
*/
public class Solution {
public static void main(String[] args) {
displayClosestToTen(8, 11);
displayClosestToTen(7, 14);
}
public static void displayClosestToTen(int a, int b) {
// write your code here
if (abs(10 - a) >= (b - 10)){
System.out.println(b);
}else {
System.out.println(a);
}
}
public static int abs(int a) {
if (a < 0) {
return -a;
} else {
return a;
}
}
}