Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Re-assigning values to variables  RSS feed

 
Vlada Den
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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
 
Ryan McGuire
Ranch Hand
Posts: 1143
9
  • Mark post as helpful
  • send pies
  • 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 ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 1143
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you posted while I was editting. Wacky!

Ryan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!