Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: StackOverFlow Error

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default StackOverFlow Error

    Hi Mentors,

    I am getting "StackOverFlow" error with my code,the code is as below:-
    //This Application displays fibonacci sequence upto the n numbers
     
    class Fibonacci
    {
    	 int upto;
    	  int result;
    /*Constructor for initializing the the max number upto which the
    *  the fibonacci sequence will be displayed
    */
    	Fibonacci(int len)
    	{
    		upto = len;
    	}
     
    //Routine to display the fibonacci sequence
    int calFib(int i)
    	{
    		System.out.println("CalFibonacci is called with::" + i);
    		if(i > upto)
    			{
    			return 1;
     
    			}
    		if(i == 0)
    		{
    			result=0;
    		}
    		if(i == 1)
    		{
    			result=1;
    		}
    		else
    			//calFibonacci(i) = calFibonacci(i-1) + calFibonacci(i-2);
    			result = calFib(i-1) + calFib(i-2);
    		return result;
    	}
     
    }
     
     
     
    class dispFibonacci {
    	public static void main(String[] args)
    	{
    		Fibonacci ob1 =new Fibonacci(10);
    		System.out.println("Displaying the fibonacci sequence upto::"+ ob1.upto);
    		int fElement;
    		for(int i = 2; i < ob1.upto; i++)
    		{
     
    			fElement= ob1.calFib(i);
    			//System.out.println(fElement);	
    		}	
    	}
     
    }

    the output with error is as below:-
    fibonacci.png

    seeking for help.

    Thanks
    Ankit


  2. #2

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: StackOverFlow Error

    Your prog is more confusing ... if u want to create Fibonacci Serise then this example can help u more.. it is very easy to understand..
    ...
    Last edited by copeg; January 13th, 2012 at 09:49 AM.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: StackOverFlow Error

    neeraj0708, please read the forums rules and the following
    http://www.javaprogrammingforums.com...n-feeding.html

Similar Threads

  1. BlinkingLabel-StackOverflow Error
    By MichaelWU in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 15th, 2011, 09:25 AM
  2. Why am I getting StackOverflow errors?
    By techcom0 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 12th, 2011, 09:18 AM