aspose file tools*
The moose likes Cattle Drive and the fly likes Say 4b Again Please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Say 4b Again Please" Watch "Say 4b Again Please" New topic
Author

Say 4b Again Please

Rashid Ali
Ranch Hand

Joined: Jan 16, 2001
Posts: 349
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
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
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

Joined: Jan 16, 2001
Posts: 349
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

Joined: Jan 16, 2001
Posts: 349
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 ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
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
 
Don't get me started about those stupid light bulbs.
 
subject: Say 4b Again Please