Reputation: 51
I am trying to write the instructions to notice when circle is about to be 12 and then add 1 to square.
The code below works fine for me
int x = Integer.parseInt(circle.getText());
x = x + 1;
String z = Integer.toString(x);
circle.setText(z);
However, I am having trouble with these new instructions I am trying to write. How can I get square, convert to integer, add 1 and then put the value back?
int q = Integer.parseInt(square.getText());
x = q + 1;
square.setText(x);
Upvotes: 3
Views: 30431
Reputation: 1
Using your own code String z = Integer.toString(x); square.setText(z);
Upvotes: -1
Reputation: 25950
Why would an int
be convertible to a String
(unless an implicit conversion exists, which is not the case, there is not a lot of implicit things with the Java compiler, primitive wrappers and string concatenation apart) ?
Use one of these two options :
square.setText(String.valueOf(x));
square.setText(x + "");
Upvotes: 0
Reputation: 393771
You can convert to String
using Integer.toString()
:
square.setText(Integer.toString(x));
Upvotes: 8