Results 1 to 3 of 3
  1. #1
    vicky82 is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Cool Please Explain me how i got this output.. I am new to java .. so please Explain me...

    public class Exercise {
    static int getAdditionalOdd(int a) {
    if (a <= 1)
    return 1;
    int x = getAdditionalOdd(a -2);
    return a + x ;
    }
    static void showOddNumbers(int a) {
    if (a >= 1) {
    System.out.println(a);
    a -= 2;
    showOddNumbers(a);
    }
    }

    public static void main(String[] args) {
    int number = 9;

    System.out.println("Odd Numbers");
    showOddNumbers(number);

    System.out.println("Sum of Odds: " + getAdditionalOdd(number));
    }
    }

    OUTPUT:
    Odd Numbers:9
    Sum of Odds: 25

    Please Explain me ow i got this Answer ... i ts confusing for me...

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,235
    Rep Power
    19

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Any one help me fix JAVA code and explain ?
    By batista11b5 in forum New To Java
    Replies: 4
    Last Post: 10-23-2010, 05:19 PM
  2. Replies: 8
    Last Post: 06-24-2010, 08:59 AM
  3. [SOLVED] Can anyone explain this pgm's output
    By haoberoi in forum New To Java
    Replies: 13
    Last Post: 11-10-2008, 01:30 PM
  4. Please explain Java
    By MarkWilson in forum New To Java
    Replies: 7
    Last Post: 07-02-2008, 08:38 AM
  5. Iam new in Java Please explain to me
    By vinaytvijayan in forum AWT / Swing
    Replies: 1
    Last Post: 12-30-2007, 11:35 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
  •