In this post, we will show you a simple program about, How to get trailing zero count in Java. The example program has been tested and shared in the post.

Example Program

package com.javatraineronline;

/**
 * 
 * @author Dinesh Krishnan
 *
 */

public class Example {

	public static int getTrailingZeroCount(int number) {
		int count = 0;

		if (number == 0)
			return count;

		while (number != 0) {
			int r = number % 10;
			if (r != 0) {
				break;
			}
			count++;
			number = number / 10;
		}

		return count;
	}

	public static void main(String[] args) {

		System.out.println("Count = " + getTrailingZeroCount(100));
		System.out.println("Count = " + getTrailingZeroCount(101));
		System.out.println("Count = " + getTrailingZeroCount(10010));
		System.out.println("Count = " + getTrailingZeroCount(100000));
	}
}

Output

Count = 2
Count = 0
Count = 1
Count = 5