This site requires JavaScript, please enable it in your browser!
Greenfoot back
XApple15
XApple15 wrote ...

2021/2/8

I cannot use Strings

XApple15 XApple15

2021/2/8

#
I have multiple Strings, named TB1. TB2, TB3 . I want to set them as text by : TB + i , i would be an integer, and i cannot manage to do that This is what i`ve done so far
Scenario1.setTextt( (String) TB + i );
I gen an error " Cannot find simbol - variable TB" Any solutions?
danpost danpost

2021/2/8

#
XApple15 wrote...
I have multiple Strings, named TB1. TB2, TB3 . ... I gen an error " Cannot find simbol - variable TB"
Where do you have them and where is the line of code located? Show entire class codes.
Super_Hippo Super_Hippo

2021/2/8

#
You can’t use parts of the variable’s name and combine the parts. You can use an array for that.
danpost danpost

2021/2/9

#
Super_Hippo wrote...
You can’t use parts of the variable’s name and combine the parts. You can use an array for that.
Example:
String[] TB = { null, TB1, TB2, TB3 };
Scenario1.setText(TB[i]);
You need to login to post a reply.