Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

return values

rootroot Posts: 103Member
how do i call a function called Fact and pass it a integer from within a class? and how do i recieve the result which is returned after function completes?
thanks,
ed.

Comments

  • zibadianzibadian Posts: 6,349Member
    [b][red]This message was edited by zibadian at 2007-1-2 10:15:46[/red][/b][hr]
    : how do i call a function called Fact and pass it a integer from within a class? and how do i recieve the result which is returned after function completes?
    : thanks,
    : ed.
    :
    Here's an example:
    [code]
    public class Fact {

    public static int fact(int someInt) {
    int i = 1;
    if (someInt > 1)
    i = someInt*fact(someInt-1);
    return i; // Returns value as result of function
    }

    }

    public class FactApp {

    public static void main(String[] args) {
    int factValue;
    factValue = Fact.fact(6); // factValue contains factorial of 6.
    }

    }
    [/code]
    Java has quite strict syntax formatting to keep the code readable. According to this formatting classes always start with a capital and class members/variables never start with capitals.


Sign In or Register to comment.