Whats wrong here?
If I wanna verify my solution, I get told that my code has to work also for negativ numbers.
But if I try it with negative numbers and run the program, the program always get the right number, so I dont understand what im doing wrong?
package de.codegym.task.task04.task0409;
/*
Am nächsten an 10
*/
public class Solution {
public static void main(String[] args) {
naechsteAnZehnAnzeigen(8, 11);
naechsteAnZehnAnzeigen(7, 14);
naechsteAnZehnAnzeigen(-3, -9);
naechsteAnZehnAnzeigen(-4, 5);
naechsteAnZehnAnzeigen(3, -5);
}
public static void naechsteAnZehnAnzeigen(int a, int b) {
if(a >= 0 && b >= 0){
int c = 10 - abs(a);
int d = 10 - abs(b);
if(abs(c) < abs(d)){
System.out.println(a);
}
else{
System.out.println(b);
}
}
else if(a < 0 && b < 0){
int e = abs(a);
int f = abs(b);
if(e < f){
System.out.println(a);
}
else{
System.out.println(b);
}
}
else if(a < 0 && b >= 0){
System.out.println(b);
}
else if(a >= 0 && b < 0){
System.out.println(a);
}
}
public static int abs(int a) {
if (a < 0) {
return -a;
} else {
return a;
}
}
}