BlueJ seems to think works properly, so after reading the failed reuirements, I saw that I should use the abs method, but I don't need the abs method!
Why must codegym limit my ingenuity with such restraints?
How can I do the task with the abs method?
package com.codegym.task.task04.task0409;
/*
Closest to 10
*/
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 c,d,e;
if (a<10){
//if less than 10, finds how much less
c=10-a;
}
else if(a==10){
//if equal to 10, sets comparison value to 0, as there is no difference
c=0;
}
else{
//if greater than 10, finds how much greater
c=a-10;
}
//same concept for b
if (b<10){
d=10-b;
}
else if(b==10){
d=0;
}
else{
d=b-10;
}
if (c>d){
System.out.println(b);
}
else if (c<d){
System.out.println(a);
}
else{
System.out.println(a);
}
}
public static int abs(int a) {
if (a < 0) {
return -a;
} else {
return a;
}
}
}