• 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

Re-assigning values to variables

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Friends!

I cannot figure out how to re-assign the values for "x" and "value" in my code, so I can get the result for different values in one run of the program:



Thanks a lot for your responces!

Vlada
 
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're asking how to run your program for different values of x without having to recompile all the time, right?

Look in the Integer class documenation. One of those methods will allow to turn a command line parameter (in args[]) into an int.

Ryan
[ April 18, 2005: Message edited by: Ryan McGuire ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure where you are on your Java Journey, so excuse me if I start with some basics. Try moving your calculation & display into a method that takes an argument. If your main looked like this:

could you imagine what the compute method might look like?

Ryan's Integer hint (posted while I was typing, you rascal! ) is a good next step, figuring out how to use a command line parameter that the user passed to main.

[ April 18, 2005: Message edited by: Stan James ]
 
Ryan McGuire
Bartender
Posts: 1205
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And you posted while I was editting. Wacky!

Ryan
 
reply
    Bookmark Topic Watch Topic
  • New Topic