How to print in a jtext as if it were a console?

0

I mean:

for (int r = 0; r < 5; r++)
    sout(r+","); //jtext.setText(r + ",")
  

0,1,2,3,4,

since in the jtext it would print only the last 4,

    
asked by JarhChuy 14.10.2018 в 00:00
source

1 answer

0

you can do it in the following way:

  • Define a String where you will store the text
  • You use your cycle to concatenate the numbers
  • Finally you put the resulting chain in your JTextField (I guess it's what you use)
  • It would be like this:

    String cad = "";
    for(int i = 1; i <= 4; i++)
        cad += i + ", ";
    jtext.setText(cad); // cad = "1, 2, 3, 4, "
    

    I hope you serve, greetings.

        
    answered by 14.10.2018 в 00:46