wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 3415
    
  12
You could pass it as a parameter


Joanne
Noam Ingalls
Ranch Hand

Joined: Jan 11, 2012
Posts: 60

Right, got it... problem fixed. Thanks.
 
jQuery in Action, 2nd edition
 
subject: How to best get value of int variable into another method?
 
Similar Threads
HashMap values-- I think I know why but how do I fix this null pointer exception?
determine the input type of the value of the function parameter map
a program
Not sure whether to override or overload methods in interface
HashMap implementation for an interpreter: cannot find symbol error