m2skills

trailing java

Apr 7th, 2017
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class trailingZeros{
  4.     public static void main(String a[]){
  5.         Scanner sc = new Scanner(System.in);
  6.         boolean cont = true;
  7.         while(cont){
  8.             System.out.print("Enter the Number : ");
  9.             int number = sc.nextInt();
  10.             countZeros(number);
  11.             System.out.print("\nDo you want to continue (1/0) : ");
  12.             int n = sc.nextInt();
  13.             if(n==0){
  14.                 cont = false;
  15.             }
  16.         }
  17.     }
  18.    
  19.     static void countZeros(int number){
  20.         int div = 5,quotient;
  21.         int zeros = 0;
  22.         while(number >= div){
  23.             quotient = number/div;
  24.             div *= 5;
  25.             zeros += quotient;
  26.         }
  27.        
  28.         System.out.println("The Trailing number of zeros in the factorial of " + number + " are : " + zeros);
  29.         return;
  30.     }
  31. }
Add Comment
Please, Sign In to add comment