# Closest to 10

• 4
• unavailable
Ten is extremely popular and attractive number. Everyone wants to be a ten. Or at least as close to it as possible. Two numbers are standing around wondering which of them is cooler. Answer: whichever is closer to ten. Let's write these numbers a displayClosestToTen method that will determine which of them is cooler.
You can't complete this task, because you're not signed in.
26 November, 22:49
Both positive and negative values ​​a and b should be considered.
SachinLevel 4 , Pune
22 November, 14:34
use temp variable to hold the result of abs() checked with abs((a-10)) and then compare the both result and return the actual value based on result.
30 September, 17:45
I don't understand why he refuses my solution even though it's good.?
RomanLevel 41
1 October, 07:01
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
MecoSLevel 8
18 September, 17:57
Sorry but i did not understand where is my error. Unsing if, using abs method, print only one number. What else?
RomanLevel 41
19 September, 06:33
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
GáborLevel 14 , Budapest
22 July, 16:55
You can put the abs(here you have the calculation for int a) < abs(calculation for int b ) to the IF condition, and the rest is just printing. :)
6 July, 08:23
I solved the problem (1-hour) but I didn't understand. lol
AbdunabiLevel 4 , Tashkent
11 June, 23:04
who is know? where do I wrong?
``````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(a-10) < abs (b-10))
{
System.out.println(a);
}
if(abs(a-10) > abs (b-10))
{
System.out.println(b);
}
if(abs(a-10) == abs (b-10)){
System.out.println(a+", "+ b);
}

}

public static int abs(int a) {
if (a < 0) {
return -a;
} else {
return a;
}
}
}``````
RomanLevel 41
12 June, 05:31
Anusha GovindarajanLevel 7 , Amsterdam
16 July, 12:54
You should use else if and else.Please check syntax. if (condition) { } else if(condition) { } else { }
5 June, 10:07
Interesting program. Enjoyed it.
ProfjLevel 20 , Lagos
1 June, 20:15
My code is working perfectly but it is not accepting it. it is displaying this error. "Be sure that the program works correctly with numbers that are equally close to 10." And it works correctly
RomanLevel 41
3 June, 06:12
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
MareikeLevel 15 , Göttingen
17 April, 16:49
After reading the help section, I got the solution correct. But I wonder, why isn't a "public static int abs(int b)" necessary? I mean it works without it, but I don't understand why?