Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-19-2008, 09:31 PM
Member
 
Join Date: Nov 2007
Posts: 11
Nari is on a distinguished road
help with recursion
Please help me.
i have exam on Monday and i can't solve some of exam problems.

exp1.

Write a recursive void method that takes a single(positive) int argument n and writes the integers 1,2,.....,n to the screen.

can anyone explain to me how to solve this type of problems.

Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-19-2008, 10:31 PM
Member
 
Join Date: Apr 2008
Location: USA
Posts: 12
JavaLovenJoe is on a distinguished road
It goes like this.
Code:
import com.blogspot.joelnkode.tutorial.java.*; public class CoolCode extends NewApplication { public void startHere() { int n = 20; new ApplicationUtils(this). recurse("recursor", n). minus(1). until(0). start(); ApplicationUtils.exit(); } public void recursor(int n) { new OutputUtils(n); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-20-2008, 04:04 AM
Member
 
Join Date: Apr 2008
Posts: 28
fireball2008 is on a distinguished road
Send a message via AIM to fireball2008
public void Output(int n)
{if(n<0)
return;
else
{Output(n-1);
System.out.println(n);}}
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-20-2008, 05:47 AM
Member
 
Join Date: Nov 2007
Posts: 11
Nari is on a distinguished road
Thanks.
can u explain how to write a main for this method.
i don't know how to call a static method in main to print random numbers.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-20-2008, 07:34 AM
Member
 
Join Date: Nov 2007
Posts: 11
Nari is on a distinguished road
got it!!!!!!!
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-20-2008, 08:54 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Do you have a book?

regards,
sukatoa
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 04-20-2008, 07:42 PM
Member
 
Join Date: Nov 2007
Posts: 11
Nari is on a distinguished road
yes i have a book, why???
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 04-21-2008, 09:01 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Quote:
Originally Posted by Nari View Post
yes i have a book, why???
How about you go through it looking for the answer to your question? Your question is a very basic one... it's crucial that you learn these concepts or you will not go far in this profession.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 04-22-2008, 03:47 AM
Member
 
Join Date: Apr 2008
Posts: 28
rico16135 is on a distinguished road
with all due respect, sometimes a straight answer is better than spending 3 hours looking for an answer in a book.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 04-22-2008, 04:12 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Quote:
Originally Posted by rico16135 View Post
with all due respect, sometimes a straight answer is better than spending 3 hours looking for an answer in a book.
Indeed- this is not one of those times- he didn't even write an attempt at his problem. Regardless, his original question was answered, and if someone doesn't know how to write the most fundamental of methods(main) then how exactly are we helping by blurting out the answer? He'll learn more from reading from a book, tutorial or online source which may lead him to experimenting with the code until he sees the light. Far more beneficial than us just giving him the answer. Keep in mind, we're not obliged to provide answers- we don't get paid for this; we devote our personal time to assisting others... you might forgive us if we choose to believe that honest people want to make an honest effort, in which case odds are they will receive real answers to their questions. The questions he had are found in just about every beginner book on Java programming- even other language programming. If it's taking you 3 hours to find an answer in a book- then the problem is not with the book where the answer exists.

Joe, unless that's recursive by the creator of the library- it's not recursive at first glance. Review fireball's example for what a recursive method looks like.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 04-22-2008, 04:19 AM
Member
 
Join Date: Apr 2008
Posts: 28
rico16135 is on a distinguished road
well, i can't disagree with anything you said
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 04-22-2008, 08:01 AM
Member
 
Join Date: Nov 2007
Posts: 11
Nari is on a distinguished road
actually we finished this chapter on Friday and i had a exam today morning, it was comprehensive exam from 13 chapters and believe me i didn't wanted to spend so much time on one problem. I wasn't able to solve few problems, i didn't know how to call static method in main ,otherwise i do know how to write a main.

but you guys r right this is really crucial time for me because this is a basic course and i need to learn these things.

anyways thanks for your help.
oh and i am not a guy!!!!

Last edited by Nari : 04-22-2008 at 08:08 AM.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 04-22-2008, 09:09 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Quote:
Originally Posted by Nari View Post
actually we finished this chapter on Friday and i had a exam today morning, it was comprehensive exam from 13 chapters and believe me i didn't wanted to spend so much time on one problem.
Strange my friend. How did you going to complete the exam on 13 chapters, your question asking here in chapter one of Java. Anyway I wish you all the best for the exam.

Quote:
Originally Posted by Nari View Post
I wasn't able to solve few problems, i didn't know how to call static method in main ,otherwise i do know how to write a main.

What you have tried. May you already take your exam. It's ok. Do those questions again see what you can do for the next .


Quote:
Originally Posted by Nari View Post
but you guys r right this is really crucial time for me because this is a basic course and i need to learn these things.
But you have finished the first chapter, right?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 04-22-2008, 09:37 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Quote:
Originally Posted by Nari View Post
oh and i am not a guy!!!!
Unless your sex is mentioned in your profile(JavaTip- maybe we can add this?), it's going to be presumed you're male due to this being predominantly a male profession- I don't mean to offend; I'm very happy to see you here. Frankly, in this profession- the more women the better.

Thanks for clearing that up!
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 04-22-2008, 10:07 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Here goes Better to change my aviator too
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 04-24-2008, 11:13 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
Basic recursion:

Code:
public Object recursiveAlg(Object o) { if( Some kind of ending sequence) { return o; // or something along these lines } else { this.recursiveAlg(o - 1); // usually o is an int or if it is an array than // it would be array[myArray.length - 1] } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help With Recursion andrew777 New To Java 1 03-29-2008 02:51 PM
recursion kdeighan New To Java 3 01-25-2008 11:48 PM
Recursion bozovilla Advanced Java 3 01-07-2008 06:53 PM
recursion ravian New To Java 2 12-03-2007 07:15 PM
Help with recursion scts102 New To Java 1 11-20-2007 12:07 AM


All times are GMT +3. The time now is 05:46 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org