Nice to meet you, i am a newbie i would like to ask a question that bothers me out :

1).How to add the decimal representation of N! (5 <= N <= 1,000,000) is simply the multiplicity of the prime factor 5 in N! to my script?
2). I wanted to ask how the output of case#3:118 became case#3:27,whether the problem is string or an Integer? and how to solve it? Could you help me out. thanks

here's my code code:

Package test;  
import java.io.BufferedReader;  
import java.io.InputStreamReader;  
import java.io.IOException;  

public class test {  
    String trailing;  
    String y;  



    /** 
     * @param args the command line arguments 
     */  

    public static void main(String[] args) throws Exception{   
    System.out.print("Sample Input:");  
    final int bilangan =inputData();      
    int trailing;  
    trailing = findTrailingZeroes(bilangan);  
        String y= String.valueOf(trailing);     
    System.out.println("The number of trailing zeroes in " + bilangan );  
    System.out.println( "factorial is " + y);  


    }  

    public static int findTrailingZeroes(int number)  
    {  
       int trailingZeroes = 0;  
       int loopCounter = 0;  

       number -= 5;  

       while (number >= 0)  
       {  
           trailingZeroes++;  
           loopCounter++;  

           if (loopCounter == 5)  
           {  
               trailingZeroes++;  
               loopCounter = 0;  
           }  

           number -= 5;  
       }  

       return trailingZeroes;  
    }  


    private static int inputData() throws IOException{  
        BufferedReader bfr =  
        new BufferedReader (new InputStreamReader(System.in));  
        String angkaInput = null;  
        try {  
            angkaInput = bfr.readLine();  
        }catch (IOException e){  
            e.printStackTrace();  
        }  
        int x = Integer.valueOf(angkaInput).intValue();  
        String y= String.valueOf(angkaInput);  
        System.out.println("Sample Output:");  
        System.out.println("");  
        switch(x)  
        {  
            case 5:  
                System.out.println("Case#1:"+y);  
                break;  
            case 10:  
                System.out.println("Case#2:"+y);  
                break;  
            case 118:  
                System.out.println("Case#3:"+y);  
                break;  
            case 211:  
                System.out.println("Case#4:"+y);  
                break;  
            default:   
        int bilangan = 0;  
            break;  
        }  
        return x;  

        }  
    }  

Output :
Sample Input:118
Sample Output:

Case#3:118
The number of trailing zeroes in 118
factorial is 27

  1. Factorials of numbers like 1,000,000 are far far too large for ordinary int or long variables; you need the BigInteger class to hold them. BigInteger also has a toString method that gives you a string version that you can print etc.

  2. I have no idea what "case 3" is supposed to do, so how can anyone tell why it's wrong? YOu need to explain this a lot better.

I wanted the result from factorial 118 is 27 put on the case#3. What should i do?
And can you send me example of BigInteger how?

Why is 27 teh correct result? What formula or algorithm are you trying to execute?

For BigInteger see the API documentation, or Google for examples.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.