Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program that calculates with how many zeroes the factorial
- * of a given number n has at its end.
- * Your program should work well for very big numbers, e.g. n=100000. */
- import java.util.Scanner;
- public class _18_TrailingZeroesInN_Factorial {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter a positive Integer number: ");
- int numN = scan.nextInt();
- scan.close();
- if (numN > 0) {
- int countZeroes = 0;
- while (numN > 4) {
- numN /= 5;
- countZeroes += numN;
- }
- System.out.printf("The Count Zeroes in that N-Factorial is: %d !\n",
- countZeroes);
- } else {
- System.out.println("Error! - Invalid Input number!!!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement