Hello. I have the following code:
float num = 205.0f;
String myString = "0";
for(int i=0;i<=5;i++){
g2D.drawString(myString,70.0f,num);
num-=20.0f;
myString+=10;
}
I am looking to increase the value of myString by 10. However, since it
is a string I can't really increment it...(Can I?), So I was wondering
If there is a simple way to achieve this. (Or any way at all really).
ttyl.

Signature
Pro'-gram 1) n. A magical spell cast over a computer which transforms
user input into error messages. 2) vt. An activity similar to banging
one's head against a wall, but with less opportunity for relief.
klynn47@comcast.net - 21 Jan 2006 02:57 GMT
Well Strings are immutable so you can can't them. However, you can
change what String the String reference myString refers to.
Allan Bruce - 21 Jan 2006 04:33 GMT
> Hello. I have the following code:
>
[quoted text clipped - 11 lines]
>
> ttyl.
You can do something like this:
int myNum = 0;
String myString = "" + myNum;
// do things and increment myNum
myString = "" + myNum;
Alternatively you can convert from String to int by:
int myInt = Integer.parseInt(myString);
HTH
Allan
Roedy Green - 21 Jan 2006 04:48 GMT
>I am looking to increase the value of myString by 10. However, since it
>is a string I can't really increment it...(Can I?), So I was wondering
>If there is a simple way to achieve this. (Or any way at all really).
see http://mindprod.com/applet/converter.html
for String > int and int > String.
If you find yourself doing this often, you might decide to keep the
int value around and only generate the String when it comes time to
play.
This thinking goes way back to COBOL COMPUTATIONAL-n variables.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
IchBin - 21 Jan 2006 05:03 GMT
> Hello. I have the following code:
>
[quoted text clipped - 11 lines]
>
> ttyl.
How about looking at it the other way around..
float num = 205.0f;
int myInt = 0;
for(int i=0;i<=5;i++)
{
g2D.drawString(Integer.toString(myInt),70.0f,num);
num-=20.0f;
myInt+=10;
}
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Hal Rosser - 22 Jan 2006 01:43 GMT
> Hello. I have the following code:
>
[quoted text clipped - 9 lines]
> is a string I can't really increment it...(Can I?), So I was wondering
> If there is a simple way to achieve this. (Or any way at all really).
If you need to increment myString so often, then maybe you should consider
using an int in the first place - and cast it to a string when you need it.
Ian Mills - 22 Jan 2006 12:49 GMT
> Hello. I have the following code:
>
[quoted text clipped - 11 lines]
>
> ttyl.
Try
float num = 205.0f;
int myInt = 0;
for(int i=0;i<=5;i++){
g2D.drawString("" + myInt,70.0f,num);
num-=20.0f;
myInt+=10;
}
fb - 23 Jan 2006 01:05 GMT
> Hello. I have the following code:
<Snip Code>
Thanks everyone. They were all very helpful answers.
fb

Signature
"Outside of a dog, a book is a man's best friend. Inside a dog, it's too
dark to read anyway." - Groucho Marx