 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to Count trailing zeroes in factorial of a number
To count trailing zeroes in factorial of a number, the Java code is as follows −
Example
import java.io.*; public class Demo{    static int trailing_zero(int num){       int count = 0;       for (int i = 5; num / i >= 1; i *= 5){          count += num / i;       }       return count;    }    public static void main (String[] args){       int num = 1000000;       System.out.println("The number of trailing zeroes in " + num +" factorial is " +       trailing_zero(num));    } }  Output
The number of trailing zeroes in 1000000 factorial is 249998
A class named Demo contains a function named ‘trailing_zero’ that initializes count value to 0, and iterates through the number whose factorial’s number of zeroes need to be found. This count is returned as output from the function. In the main function, the value fro ‘num’ is defined, and this function is called by passing this number as a parameter. Relevant messages are displayed on the console.
Advertisements
 