public class Solution {
public static void main(String[] args) {
displayClosestToTen(8, 11);
displayClosestToTen(7, 14);
displayClosestToTen(8, 12);
}
public static void displayClosestToTen(int a, int b) {
int num1 = 10 - a;
int num2 = 10 - b;
int absa = abs(num1);
int absb = abs(num2);
if (absa > absb)
{
System.out.println(b);
}
else if(absb > absa)
{
System.out.println(a);
}
else
{
System.out.println(a + " " + b);
}
}
public static int abs(int a) {
if (a < 0) {
return -a;
} else {
return a;
}
}
}
O/P
11
7
8 12
Task failed to pass even though getting correct output
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
12 November 2019, 16:02
need to see full code. Attach full solution when asking for help.
0