It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Java Forum

Don't understand about Recursive Method

Don't understand about Recursive Method

Postby SexyFlip on Sun Mar 18, 2007 9:13 pm

I don't understand this example at all.. how can i ask user for input and then check for the size?

Code: Select all
   public int mystery(int a[], int size)
   {
   
   if ( size==1)
   return a[0];

   else
   return a[size-1] + mystery(a,size-1);
   }
}
[/quote]
SexyFlip
 
Posts: 0
Joined: Sun Mar 18, 2007 9:05 pm

Re: Don't understand about Recursive Method

Postby raju_neve on Wed Apr 04, 2007 8:45 am

SexyFlip wrote:I don't understand this example at all.. how can i ask user for input and then check for the size?

Code: Select all
   public int mystery(int a[], int size)
   {
   
   if ( size==1)
   return a[0];

   else
   return a[size-1] + mystery(a,size-1);
   }
}
[/quote]


size variable is not represent the size of array , it is number of elements in array a[] which user wants to add.
This function will addition of first three elements if i call the above method like mystery(a,3);
raju_neve
 
Posts: 0
Joined: Wed Apr 04, 2007 8:33 am
Location: Mumbai


Who is online

Users browsing this forum: No registered users and 2 guests