- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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.
- Related Articles
- Python Program to Count trailing zeroes in factorial of a number
- C/C++ Program to Count trailing zeroes in factorial of a number?
- C/C++ Programming to Count trailing zeroes in factorial of a number?
- Factorial Trailing Zeroes in C++
- Count trailing zeros in factorial of a number in C++
- Java Program to Find Factorial of a number
- C program to find trailing zero in given factorial
- C Program to count trailing and leading zeros in a binary number
- Program to find trailing zeros in factorial of n in C++?\n
- Java Program to Find Factorial of a Number Using Recursion
- Finding trailing zeros of a factorial JavaScript
- Java program to print the factorial of the given number
- Java program to find the factorial of a given number using recursion
- Swift Program to Find Factorial of a number
- Kotlin Program to Find Factorial of a number

Advertisements