Results 1 to 4 of 4
- 12-13-2010, 06:58 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
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 how i got this Answer ... it's confusing for me...
- 12-13-2010, 07:12 AM #2
- 12-13-2010, 07:14 AM #3
I'll do better than that. I'll point you to a tutorial where you can learn to understand it for yourself.Please Explain me how i got this Answer
The Java™ Tutorials
Oh, and next time, do your own homework. You don't learn anything by copy/paste.
db
- 12-13-2010, 07:22 AM #4
Also cross posted here:
Please Explain me how i got this output.. I am new to java .. so please Explain me... - Java Programming Forums
Any more?
db
Similar Threads
-
Please Explain me how i got this output.. I am new to java .. so please Explain me...
By vicky82 in forum New To JavaReplies: 2Last Post: 12-13-2010, 01:34 PM -
Could you plese explain somebody how come output of these codes.
By moonlanka in forum New To JavaReplies: 8Last Post: 06-24-2010, 08:59 AM -
[SOLVED] Can anyone explain this pgm's output
By haoberoi in forum New To JavaReplies: 13Last Post: 11-10-2008, 01:30 PM -
Please explain Java
By MarkWilson in forum New To JavaReplies: 7Last Post: 07-02-2008, 08:38 AM -
Iam new in Java Please explain to me
By vinaytvijayan in forum AWT / SwingReplies: 1Last Post: 12-30-2007, 11:35 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks