StackOverflow?

Discussion in 'Java' started by state, Sep 14, 2011.

  1. state

    state New Member

    Joined:
    Sep 14, 2011
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    Hello everyone.I have just joined the forum.
    Kindly help me with the source code to find the largest prime factor of a 12-digit number.
    HTML:
    import java.io.*;
    import java.util.Scanner;
    class primefactor
    {
        public static void main(String args[])
        {
            try{
            long num,i,j,count=0L,rem;
            long ans=0L;
            System.out.println("Enter the number whose greatest prime factor is required:");
            Scanner sc=new Scanner(System.in);
            num=sc.nextLong();
            for(i=1;i<=num;i++)
            {
            
                for(j=1;j<=i;j++)
                {
                    if(i%j==0)
                        count=count+1;
                    
                }
                if(count==2)
                {
                    rem=num%i;
                    if(rem==0)
                        ans=i;
                        
                    
                }
                count=0;
            }
            System.out.println("The answer is "+ ans);}
            catch(Exception e){System.out.println(e.getMessage());}
        }
    }
    
    Thank You
     
  2. ManzZup

    ManzZup New Member

    Joined:
    May 9, 2009
    Messages:
    278
    Likes Received:
    43
    Trophy Points:
    0
    Occupation:
    Production Manager:Software @ ZONTEK
    Location:
    Sri Lanka
    Home Page:
    http://zontek.zzl.org
    How does StackOverflow relates here and please explain the process you have folowed so far
     
  3. state

    state New Member

    Joined:
    Sep 14, 2011
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    I didn't follow any process.I am not even sure that this is a stack overflow error.
     
  4. georgemaravich

    georgemaravich New Member

    Joined:
    Dec 2, 2014
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    What do you mean? StackOverflow erro is thrown when a stack overflow occurs because an application recurses too deeply.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice