Hello together,
maybe I'm just to stupid for this task. I had to google and get the solution via Stackoverflow.
Without that I wouldn't be able to find a solution.
Could someone please explain to me with some examples?
I really want to understand it... the absolute value is something I don't understand as well.
It gives us simply the positive value of our one, but how does this help us to find the number nearest to 10?
Thank you!
public class Solution {
public static void main(String[] args) {
naechsteAnZehnAnzeigen(8, 11);
naechsteAnZehnAnzeigen(7, 14);
}
public static void naechsteAnZehnAnzeigen(int a, int b) {
int a1 = abs(a - 10);
int b1 = abs(b - 10);
if (a1 < b1)
{
System.out.println(a);
}
else
System.out.println(b);
}
public static int abs(int a) {
if (a < 0) {
return -a;
} else {
return a;
}
}
}