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 2 of 2

Thread: trying to pass default params to tail recursion function

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

    Default trying to pass default params to tail recursion function

    In this code:

    	public static void main(String[] args) {
    		System.out.println(tailrecsum(5,0));
    	}
     
    	private static int tailrecsum(int x,int running_total, int default_total){
    		if(x == 0){
    			return running_total;
    		}
    		else {
    			return tailrecsum(x-1, running_total+x);
    		}
    	}

    I get an error "The method tailrecsum(int, int, int) in the type MainClass is not applicable for the arguments (int, int)"
    on this line:

    return tailrecsum(x-1, running_total+x);

    I know java doesn't support default parameters, so I use overloading, but not sure why I get the error.


  2. #2
    Member
    Join Date
    Jul 2012
    Posts
    119
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default Re: trying to pass default params to tail recursion function

    you define 3 parameters in tailrecsum(int, int, int) but invoke with 2 parameters in return tailrecsum(int, int)

Similar Threads

  1. default Value of char
    By chronoz13 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 12th, 2011, 09:25 AM
  2. [SOLVED] How to choose a different toString() Besides the default one?
    By Hallowed in forum Java Theory & Questions
    Replies: 12
    Last Post: April 8th, 2011, 03:05 PM
  3. 'pass by value' and 'pass by reference'
    By pokuri in forum Object Oriented Programming
    Replies: 5
    Last Post: January 26th, 2011, 11:30 AM
  4. How to Pass unlimited Arguments to a Function
    By neo_2010 in forum Java Programming Tutorials
    Replies: 2
    Last Post: July 8th, 2009, 11:39 AM
  5. How to Pass unlimited Arguments to a Function
    By neo_2010 in forum Java Code Snippets and Tutorials
    Replies: 2
    Last Post: July 8th, 2009, 11:39 AM

Tags for this Thread