|
|
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.
|
|

04-19-2008, 09:31 PM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 11
|
|
|
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.

|
|

04-19-2008, 10:31 PM
|
|
Member
|
|
Join Date: Apr 2008
Location: USA
Posts: 12
|
|
It goes like this.
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);
}
}
|
|

04-20-2008, 04:04 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 28
|
|
|
public void Output(int n)
{if(n<0)
return;
else
{Output(n-1);
System.out.println(n);}}
|
|

04-20-2008, 05:47 AM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 11
|
|
|
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.
|
|

04-20-2008, 07:34 AM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 11
|
|
|
got it!!!!!!!
|
|

04-20-2008, 08:54 AM
|
 |
Senior Member
|
|
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
|
|
|
Do you have a book?
regards,
sukatoa
|
|

04-20-2008, 07:42 PM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 11
|
|
|
yes i have a book, why???
|
|

04-21-2008, 09:01 PM
|
 |
Moderator
|
|
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
|
|
Originally Posted by Nari
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)
|
|

04-22-2008, 03:47 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 28
|
|
|
with all due respect, sometimes a straight answer is better than spending 3 hours looking for an answer in a book.
|
|

04-22-2008, 04:12 AM
|
 |
Moderator
|
|
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
|
|
Originally Posted by rico16135
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)
|
|

04-22-2008, 04:19 AM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 28
|
|
well, i can't disagree with anything you said 
|
|

04-22-2008, 08:01 AM
|
|
Member
|
|
Join Date: Nov 2007
Posts: 11
|
|
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.
|
|

04-22-2008, 09:09 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
|
|
Originally Posted by Nari
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.
Originally Posted by Nari
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 .
Originally Posted by Nari
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.
|
|

04-22-2008, 09:37 AM
|
 |
Moderator
|
|
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
|
|
Originally Posted by Nari
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)
|
|

04-22-2008, 10:07 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,610
|
|
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.
|
|

04-24-2008, 11:13 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
Basic recursion:
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]
}
}
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
| 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 |
|
|