public class Solution {
public static void main(String[] args) {
displayClosestToTen(8, 11);
displayClosestToTen(7, 14);
}
public static void displayClosestToTen(int a, int b) {
if (abs(10-a)<abs(10-b))
System.out.println(a);
else if (abs(10-b)<abs(10-a))
System.out.println(b);
else
System.out.println(a +" "+ b);
}
public static int abs(int a) {
if (a < 0) {
return -a;
} else {
return a;
}
}
}
It is not passing this test: The displayClosestToTen method should display a number on the screen in accordance with the task conditions. Can someone help with this please🙏
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Maryem Vickers
7 July 2020, 17:42
Oh haha
0
Jakhongir Ruziev QA Automation Engineer at Exadel
3 April 2020, 01:44solution
I was displaying two numbers if both are equally close to ten. But the task says to display either of them which mean one number.
+2