# Convert last non zero digit of the number to 0

I need to write a program that would convert the last non zero digit of the number to 0, till all digits (except the first one are converted to 0). For instance, if the number supplied is "11550", then it should print
11500
11000
10000

similarly, if number supplied is 11841, then it should print
11840
11800
11000
10000

In my code, I am able to iterate over the digits

``````public class NumConversion {

public void convert(String strNum) {
int number = Integer.parseInt(strNum);

int tmp = 0;
while(number > 0) {
tmp = number % 10;
number /= 10;
System.out.println(tmp);
}

}

public static void main(String[] args) {
new NumConversion().convert("11550");

}

}
``````

But I am not able to make out how to then transform the number? Do I need to replace the last digit and then append a 0 ?

Thank you
LVL 1
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
You'd probably be better off treating the number as a string
Commented:
You could do something like the following.
``````convert(String s){
int number = Integer.parseInt(s);
for(int x = 10 ; 0 < number/x  ; x *= 10){
int r = (number/x) * x;
if(r != number)System.out.println(r);
}
}
``````

Experts Exchange Solution brought to you by