Android For loop

前端 未结 1 404
旧时难觅i
旧时难觅i 2021-02-07 21:40

I have the following code...

String t = \" \"; 
for(int l=0; l<=5; l++){
    t = \"Num: \" + l + \"\\n\";
}

VarPrueba.setText(t);

I am want

1条回答
  •  星月不相逢
    2021-02-07 22:04

    Change as follow:

    t+="Num: " + l + "\n";
    

    And the most effective way to do this is to using StringBuilder, Something like:

    StringBuilder t = new StringBuilder(); 
    for(int l=0; l<=5; l++){
        t.append("Num:");
        t.append(l+"\n");
    }
    
    VarPrueba.setText(t.toString());
    

    0 讨论(0)
提交回复
热议问题