Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need help using Recursive method to print increasing numbers 1 thru n

843789Feb 20 2010 — edited Feb 21 2010
I know how to print out number decreasing using a Recursive method:

public static void CountDown2(int n)
{ if(n < 0) n = - n;

if(n > 0){
System.out.print(" " + n);
CountDown2(n - 1);}

}

So how can you print out the numbers with 1 through n? I guess the base case would be the original integer n, but I am still not sure how to do this. Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 21 2010
Added on Feb 20 2010
4 comments
491 views