When we enter a no like "00982787878" (having 9 digits and zeros) the output should not be displayed after the zeros are trimmed.
Problem:
There is some problem in while loop as the output is a number with just one 0 trimmed.
Code:
public static String trimZeros(String mobNumber)
{
boolean exitLoop = true;
int count = 0;
while (exitLoop && mobNumber.substring(count) == "0")
mobNumber = mobNumber.substring(0);
if (mobNumber.charAt(count) != '0')
{
exitLoop = false;
}
count++;
mobNumber = mobNumber.replaceAll(" ", "");
mobNumber = mobNumber.length() < 10 ? mobNumber.substring(mobNumber
.length()) : mobNumber.substring(mobNumber.length() - 10);
return mobNumber;
}