• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 60
Firefox Browser Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:




 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could pass it as a parameter
 
Noam Ingalls
Ranch Hand
Posts: 60
Firefox Browser Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, got it... problem fixed. Thanks.
 
I am mighty! And this is a mighty small ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic