Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By KevinWorkman

Thread: How to Pass a variable from method to method

  1. #1
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default How to Pass a variable from method to method

    How do you pass a variable from method to method in Java?

    I tried declaring the variable as public static int max; but that didn't work :(

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,932
    Rep Power
    8

    Default Re: How to Pass a variable from method to method

    DarrylBurke likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: How to Pass a variable from method to method

    So if I am understanding the reading properly, I would just do it like this:
    Java Code:
    Public static void (String[] args)
    {
    int nameyourprice;
    //more code here
    }
    Public static void (int nameyourprice)
    {
    //more code here
    }
    Is that correct?

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,932
    Rep Power
    8

    Default Re: How to Pass a variable from method to method

    Quote Originally Posted by Rahim2312 View Post
    So if I am understanding the reading properly, I would just do it like this:
    Java Code:
    Public static void (String[] args)
    {
    int nameyourprice;
    //more code here
    }
    Public static void (int nameyourprice)
    {
    //more code here
    }
    Is that correct?
    No, and it contains syntax errors. What happened when you tried to compile this?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: How to Pass a variable from method to method

    I haven't tried to compile it yet.

  6. #6
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: How to Pass a variable from method to method

    A compile error of this:
    required: int
    found: no arguments
    reason: actual and formal argument lists differe in legth

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: How to Pass a variable from method to method

    Maybe you need to spend a little more than 21 minutes to go through the tutorial Kevin recommended?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    Rahim2312 is offline Member
    Join Date
    Apr 2012
    Posts
    88
    Rep Power
    0

    Default Re: How to Pass a variable from method to method

    I was able to figure it out...thank you for the provided link, and assistance.

Similar Threads

  1. Replies: 1
    Last Post: 10-27-2011, 07:16 AM
  2. Can we pass Parameter to the method through properties File.
    By deshmukh.niraj04 in forum New To Java
    Replies: 2
    Last Post: 04-18-2011, 09:41 AM
  3. Replies: 18
    Last Post: 04-18-2011, 05:39 AM
  4. pass value inside method A to method B
    By masokis in forum New To Java
    Replies: 5
    Last Post: 09-01-2010, 04:06 AM
  5. Pass String[] into method in different class
    By Swankee in forum New To Java
    Replies: 19
    Last Post: 09-28-2009, 05:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •