Привет всем! Чет я застрял.
Не смотря что вывод в консоль правильный при любых кейсах на вход
проверка возвращает:
"Не выполнены все требования задачи! "
"Метод displayClosestToTen должен выводить число на экран согласно заданию."
package com.javarush.task.task04.task0409;
/*
Ближайшее к 10
*/
public class Solution {
public static int numb = 10;
public static void main(String[] args) {
displayClosestToTen(8, 11);
displayClosestToTen(7, 14);
displayClosestToTen(-7, 14);
displayClosestToTen(22, 14);
displayClosestToTen(22, -14);
}
public static void displayClosestToTen(int a, int b) {
System.out.println(compareDifference(a, b));
}
// Compare the difference args to args.
public static int compareDifference(int a, int b) {
if (getDifference(a) < getDifference(b)) {
return a;
} else { // if (abs(b) < abs(a)) {
return b;
}
}
// Calculate the difference numb to args.
public static int getDifference(int a) {
if (abs(a) < numb) {
return (numb - abs(a));
} else if (abs(a) > numb) {
return (abs(a) - numb);
} else {
return abs(a);
//System.out.println("The number " + a + " is equal to 10");
}
}
// Get absolut value of arguments.
public static int abs(int a) {
if (a < 0) {
return (-a + numb);
} else {
return a;
}
}
}