The challenge is to remove any Zeros at the end of the number. Zeros within a two number are okay. EG:
14000 == 14 //all end zeros removed
10300 == 103 // all end zeros removed
I wrote this function to solve the problem:
public class NoBoring {
public static int noBoringZeros(int n) {
System.out.println(n); // testing
System.out.println(Math.abs(n % 10)); //testing
if(Math.abs(n % 10) != 0){
return n;
}
return noBoringZeros(n/10);
}
}
Unfortunately this doesnt work for negative inputs. See my output of the test case below:
//LD = last digit of the number
//ZR is the zero removed
Fixed Tests: noBoringZeros
1450
0 //LD
145 //ZR
5 //LD
960000
0 //LD
96000 //ZR
0 //LD
9600 //ZR
0 //LD
960 //ZR
0 //LD
96 //ZR
6 //LD
1050
0 //LD
105 //ZR
5 //LD
-1050
0 //LD
-105 //ZR
5 //LD
-105
5
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
I dont understand fully why this is failing? I would have thought the drop out statement of n % 10 not = 0 would cause the return of n but it doesnt seem todo that for negative numbers?