Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下代码...
String t = " "; for(int l=0; l<=5; l++){ t = "Num: " + l + "\n"; } VarPrueba.setText(t);
我想遍历一组数字,并生成一个String在最后列出它们的数字。输出应该是这样的......
String
1 2 3 4 5
有人可以帮助我了解如何更正我的代码。
更改如下:
t+="Num: " + l + "\n";
最有效的方法是使用StringBuilder,例如:
StringBuilder
StringBuilder t = new StringBuilder(); for(int l=0; l<=5; l++){ t.append("Num:"); t.append(l+"\n"); } VarPrueba.setText(t.toString());