Results 1 to 2 of 2
  1. #1
    amtrbz is offline Member
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Smile Simple Java Methods Help...

    Hi, I am working on a simple program where in one of the classes i have to add a static method which recursively divides a passed integer by 2 and returns a count of number of calls it takes to reach 1??

    I also have to Add a static method called "sumofcharacters" to my Recursion class that recursively sums the character values in a passed string and returns the sum. Can some one help me with how to return a count of number of calls and method that computes sums of the character values in a passed string...

    this is what i have so far....

    public static int intlog2(int n) {
    if (n == 1)
    return 1;
    else
    return intlog2(n/2);
    }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You are pretty much there, except for this just tests if the input is 1, if it is it returns 1, else it recursively goes on with half the input, it needs to count somehow each time it calls itself. Do it in your head following this thought, when do you change the count?

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Static Builder and Create Methods for simple class
    By Pilot Ace in forum New To Java
    Replies: 3
    Last Post: 08-30-2009, 10:18 AM
  3. Need help with java methods
    By dumas64 in forum Networking
    Replies: 1
    Last Post: 08-08-2009, 06:28 PM
  4. JSP functions and Java Bean methods
    By lisa.lipsky in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 07-07-2009, 07:29 AM
  5. Methods of the java.util.Vector
    By ajeeb in forum New To Java
    Replies: 3
    Last Post: 12-26-2008, 03:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •