Results 1 to 3 of 3
- 09-14-2011, 03:27 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 11
- Rep Power
- 0
using variables in multiple methods
I have three methods:
method 1 gets an integer from the user and stores it in int x.
method 2 gets another integer from the user and stores it in int y.
method 3 performs the equation x * y and returns the value.
How can I get the values of x and y into method 3 so it can do the equation?
- 09-14-2011, 03:43 AM #2
Member
- Join Date
- Sep 2011
- Posts
- 23
- Rep Power
- 0
Re: using variables in multiple methods
I believe you would have to create a separate method for x and y then call that method x,y() in the main method
- 09-14-2011, 03:44 AM #3
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: using variables in multiple methods
You can do this two ways, either have the methods return an int,
Or you can have instance variables which the first two methods set, and the third method creates.Java Code:System.out.println(method3(method1(), method2()));
Similar Threads
-
Static variables and methods
By sudharani in forum New To JavaReplies: 5Last Post: 04-25-2011, 02:07 PM -
Using variables inside methods?
By Forty0ztoFreedom in forum New To JavaReplies: 2Last Post: 04-08-2011, 07:36 PM -
How to get methods to see variables in other methods
By ejs7597 in forum New To JavaReplies: 4Last Post: 04-03-2009, 06:36 AM -
variables-methods
By Warren in forum New To JavaReplies: 1Last Post: 11-28-2007, 04:14 PM -
significance of static variables and methods
By imran_khan in forum New To JavaReplies: 4Last Post: 08-02-2007, 09:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks