
-----------------------------------
Krocker
Wed Oct 16, 2013 3:43 pm

Methods
-----------------------------------
im creating a program which requires me to pass 2 variables to an another method in the same class. However, i have no idea how to do it as its my 1st time working with multiple methods. So i have one method that collects 2 double variables from the user in the main method, then i need to transfer those two variables to another method that does some calculations. how would i transfer those 2 variables?

-----------------------------------
DemonWasp
Wed Oct 16, 2013 7:00 pm

RE:Methods
-----------------------------------
In what way are the first method and the second method different?

Why can't you pass the arguments from (first) to (second) the same way you pass from (main) to (first)?

-----------------------------------
Krocker
Wed Oct 16, 2013 7:22 pm

RE:Methods
-----------------------------------
i dont quite understand what u mean by the same way as first and second. Im required to do an assignment that asks to create 2 methods, one that does the calculation and the other gets the input. however, there are 2 input variables and i dont know how to transfer the variables from one method to another.

-----------------------------------
DemonWasp
Wed Oct 16, 2013 7:34 pm

RE:Methods
-----------------------------------
Here's an example for one argument, of type int. You should be able to extrapolate...


public class Example {
    public static void main ( String

-----------------------------------
Krocker
Wed Oct 16, 2013 7:50 pm

RE:Methods
-----------------------------------
ok, so wat if theres 2 variables such as x and y, how would i do that?

-----------------------------------
Nathan4102
Wed Oct 16, 2013 7:56 pm

Re: Methods
-----------------------------------
Replace the 5 in the main method with your variable. If you have multiple variables, make the method accept multiple parameters.

If you aren't sure how to do that, [url=http://www.homeandlearn.co.uk/java/java_method_parameters_part2.html]this site summaries it.

-----------------------------------
Krocker
Wed Oct 16, 2013 8:00 pm

RE:Methods
-----------------------------------
oh ok
