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 08-06-2007, 01:04 AM
Member
 
Join Date: Jun 2007
Posts: 14
bluekswing is on a distinguished road
invoking method and output questions
Quick question

Code:
public static int fun(int n, int k) { if (k<= 0) return 2; if (k>=n) return 5; return fun(n-1, k-1) + fun(n-1, k); }

Trying to get a feel for methods and how they work, especially being able to look at methods and try to tell what they do and what types of output I would get. For the above example, suppose I invoke the method with the following parameters fun(5,2), what would my output be?


Also, how would I invoke this method in my main()?



Much appreciate the help as always!

Last edited by levent : 08-06-2007 at 01:51 AM. Reason: bluekswing: please do not forget to place [code] tag around your code segments.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-06-2007, 08:36 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
public static void main(String[] args) { int n = fun(5,2); System.out.println("n = " + n); } public static int fun(int n, int k) { if (k<= 0) return 2; if (k>=n) return 5; return fun(n-1, k-1) + fun(n-1, k); }
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
[SOLVED] Invoking a Stateful Session Bean as Stateless JThangiah Enterprise JavaBeans 3 07-17-2008 11:35 AM
questions Gilgamesh New To Java 3 11-28-2007 01:18 AM
3 Questions hiranya AWT / Swing 4 11-14-2007 06:57 AM
Invoking superclass methods... how? rhobincu New To Java 7 08-09-2007 05:10 PM
mapping servlets in user defined xml file and invoking them praneeth Advanced Java 0 07-16-2007 10:45 PM


All times are GMT +3. The time now is 10:29 PM.


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