I am getting expected result, But system not accepting. Can some one review and support on this. Thanks
package com.codegym.task.task04.task0409;
/*
Closest to 10
*/
interface NumericTest {
boolean computeTest(int n);
}
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
int num = 10;
int cVal;
int aVal = 0;
int bVal =0;
a = (a < 0) ? a : abs(a);
b = (a < 0) ? b : abs(b);
aVal = (num < a) ? a - num : num - a;
bVal = (num < b) ? b - num : num - b;
cVal = (aVal < bVal || aVal == bVal) ? a : b;
System.out.println(cVal);
}
public static int abs(int a) {
if (a < 0) {
return -a;
} else {
return a;
}
}
}