This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to best get value of int variable into another method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to best get value of int variable into another method?" Watch "How to best get value of int variable into another method?" New topic
Author

How to best get value of int variable into another method?

Noam Ingalls
Ranch Hand

Joined: Jan 11, 2012
Posts: 60

I've got an int that I need to pass into another class's method; what's the best way for me to do that? Declare the int as static? Although it wouldn't help right? Make it a separate method? Or try and use setters and getters which I don't really understand?

The int is keeping track of how many lines have been processed; I set up a loop to read the lines in the array myString, and used a variable called lineCounter to keep track in the method parseCommands in the main. Now I need the value of lineCounter to be passed into this class EndStatement; not sure how to get it in there though. Can someone help, or link to an example that shows how? Thanks!



Class I need to get the variable into:





"How do you define fool?"
"I don't attempt it. I wait for demonstrations. They inevitably surpass my imagination."
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3506
    
  14
You could pass it as a parameter


Joanne
Noam Ingalls
Ranch Hand

Joined: Jan 11, 2012
Posts: 60

Right, got it... problem fixed. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to best get value of int variable into another method?