Like in the video, I have made a string “ans” and added the “\n” after every row but still when when it gets printed in the text field, the rows are not being printed in separate lines.
Here is my code:
String symbol = txtChar.getText();
//Get the no. of rows entered by user
int n = Integer.parseInt(txtRows.getText());
String ans = "";
for(int row = 1; row <= n; row++){
for(int col = 1; col <= row; col++){
ans = ans + symbol;
}
ans = ans + "\n";
}
txtPattern.setText(ans);