Results 1 to 4 of 4
  1. #1
    faust83 is offline Member
    Join Date
    May 2012
    Posts
    12
    Rep Power
    0

    Default Send the value of a variable to process it in a different method

    So I'm trying to convert fractions into decimals and I have several methods... add, substract, etc...

    the result is always in a fraction format: a / b, but I need to send the results of each method to another method "convertDecimal"

    I'm having a hard time understanding how to invoke variables between methods...

    how should I do this?

    where should I declare my variable? and how can I use it in the convertDecimal method?

    I hope you guys can help me...

    thanks.



    Java Code:
      public static void convertDecimal(Fraccion fraccionX)
        {
            double decimal;
            decimal= fraccionX.getValue();
            System.out.println("\nResults;");
            System.out.println("Result in Decimal = "+decimal);       
            
            
        }
    
    
      public static void method1(Fraccion fraccionA, Fraccion fraccionB)
        {
            Fraccion c = fraccionA.sumar(fraccionB);
            System.out.println("\nRESULTADO:");
            System.out.println("A + B = "+c);    
      
        }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Send the value of a variable to process it in a different method

    where should I declare my variable
    If a variable is only used in one method, define it in that method.
    If more than one method needs access to the variable, define it as a class variable.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    faust83 is offline Member
    Join Date
    May 2012
    Posts
    12
    Rep Power
    0

    Default Re: Send the value of a variable to process it in a different method

    sorry to ask again but how do you define a class variable?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: Send the value of a variable to process it in a different method

    Put the definition inside of the {}s that define the class and outside of any methods:
    Java Code:
    class TheClass {
      int aClassVariable;
      ...
    } // end class TheClass
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: 10-27-2011, 07:16 AM
  2. Replies: 18
    Last Post: 04-18-2011, 05:39 AM
  3. Process.waitFor() method hangs application.
    By simmi in forum New To Java
    Replies: 2
    Last Post: 02-10-2010, 03:35 AM
  4. Replies: 4
    Last Post: 11-26-2009, 09:40 AM
  5. How to get variable values at runtime in another process
    By murali_java in forum Advanced Java
    Replies: 0
    Last Post: 11-02-2007, 08:03 AM

Posting Permissions

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