Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , ,

Sponsored Links


Recursion in java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 19-11-2009
Member
 
Join Date: Jul 2009
Posts: 127
Recursion in java

Sponsored Links
Hi
I am trying to write an static recursive method that returns the occurrence a particular digit d in an integer n. For example, if passed (1342457,4) it should return 2, whereas when passed (1342457,6) it should return 0. This is not my actual code and it will not sound like that, I just want help with the logic in this. I can't grasp what needs to be done. i should also take care of that no variables are other than the two that the user will input as the integer, and the digit to be checked for.

Reply With Quote
  #2  
Old 19-11-2009
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,278
Re: Recursion in java

Hi
I think you need to use at least one more variable. I think you should read the integer in as a string. Create an array of all it's char's and then compare each one to the digit. Hope this will solve your problem. If not do post back again.
Reply With Quote
  #3  
Old 19-11-2009
Member
 
Join Date: Jul 2009
Posts: 127
Re: Recursion in java

Hi
Thanks for replying. I will take care of what you have said. I am posting my code below see if you can help me.
Code:
// Returns the largest element in an integer array
public static int maxa(int[] a, int size)
{
if (size==1)
return (a[0]);
else
{
int temp = maxa(a, size-1);
if(temp>a[size-1])
return temp;
else
return a[size-1];
}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Recursion in java"
Thread Thread Starter Forum Replies Last Post
Iteration and recursion in C++ language Kim|ball Software Development 4 27-06-2011 10:32 AM
JAVA/Stutter.J.2 is a virus or any kind of java file GaganjyotTechie Networking & Security 6 29-05-2011 09:55 AM
How to Disable Recursion on the DNS Server Aliki Networking & Security 5 12-12-2010 06:36 PM
Java Programming using Adventnet SNMP Java API ROCKING_Suhas Software Development 5 17-07-2010 06:52 AM
Link List Example in Java Sample program in Java trickson Software Development 2 04-08-2009 08:23 PM


All times are GMT +5.5. The time now is 12:37 PM.