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

similarly, if number supplied is 11841, then it should print

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;
	public static void main(String[] args) {
		new NumConversion().convert("11550");



Open in new window

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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

You'd probably be better off treating the number as a string
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);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.