• 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

Say 4b Again Please

 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my nitpicked reply for the above assignment i was asked not to use the global variable in my class and they should be avoid to use.
I am agree with it but the scenario is that i am using these static class variable in a method and then in main() as well therefore i applied them so that i can access them from both the methods.
How can i overcome with this problem. Should i keep my variable as local an should do all the routine in a method.
You guys have done this and would you please revert back to me with your valuable suggestions.
Thanking you in advance.
Rashid Ali
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, what you should do depends on what exactly you are doing. If you need it in both methods, but the data for the variable isn't changing, make it static final at the class level. This avoids the whole "global variable" issue.
If the data will change, why not pass the value to your method, and work on it there?
Hope that helps some.
Jason
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jason for your quick reply. I will again re-think the whole program and try to sort out the things in light of your opinion.
By the way your post number is just sweet now and looks very nice i.e. 786. I wish it gets more than 786*786
Kind regards
Rashid Ali
[ February 12, 2002: Message edited by: Rashid Ali ]
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks
I have changed the structure of my Say-4b and have solved the issue of global variables and now using them where i need of them.
Now the problem is that 1 of the 4 methods which takes longer value from 9 digits to onward, is showing the error something like;
...
found: long
required: int
I need a long value to handle the larger number at the time of division inside of the array to pick the value from an array of string.
You guys must have overcome the problem and i request you to please suggest me a way to figure this problem out and can be able to submit my next attempt.
Thank you very much in advance.
Rashid Ali
 
jason adam
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a long, and you want to divide it, and expect an int as a result, just cast the result, something like:
(int)longValue/divisor
 
A wop bop a lu bob a womp bam boom. Tutti frutti 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