java - Display ouput of AVL Tree traversals on multiple lines in JTextArea -
for(int i=0; < list.length; i++) { system.out.printf(" %2d",list[i]); // formats right justified if ((i+1)%10==0) { system.out.println(); // adds new line after 10 values } }
i'm trying display output of avl tree inorder, preorder, , postorder traversals on multiple lines in jtextarea(), preferably 10 numbers line. tried in jtextarea() adding 5 , 10 jtextarea() parameter (jtextarea(5, 10)), doesn't work. if so, how can 'for' loop provided altered accomplish this? thank help.
i think need (efficient) "string aggregating object":
stringbuilder sb = new stringbuilder();//before loop
(string + string + string ..is considered ineffcient, possible)
in loop, populate sb
:
for (int = 0; < list.length; i++) { sb.append(string.format(" %2d", list[i])); // formats right justified if ((i + 1) % 10 == 0) { sb.append(system.lineseparator()); // adds new line (windows or unix like) after 10 values } }
(@see stringbuilder, string.format, system.lineseparator)
and after can set text of textarea like:
myjtextarea.settext(sb.tostring());
Comments
Post a Comment