我有一個由列和行組成的二維數組,當它計算出它構建矩陣或矩陣中的值時,問題是我的文本區域是隻顯示我的最終結果在我的2D數組,而不是所有其他的,但在我的控制檯在NetBeans它顯示所有的值我怎麼可能改變我的代碼來啓用this.Below是我認爲是問題的片斷。謝謝爲什麼我不能在我的文本區域中顯示我的二維數組的值
這是我actionperform按鈕顯示
for (int i =0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
matrix_tf.setText(String.valueOf(matrix[i][j]));
,這是代碼來計算我的矩陣
private void build_matrix() {
String seq1 = sequence1_tf.getText();
String seq2 = sequence2_tf.getText();
int r, c, ins, sub, del;
rows = seq1.length();
cols = seq2.length();
matrix = new int [rows][cols];
// initiate first row
for (c = 0; c < cols; c++)
matrix[0][c] = 0;
// keep track of the maximum score
max_row = max_col = max_score = 0;
// calculates the similarity matrix (row-wise)
for (r = 1; r < rows; r++)
{
// initiate first column
matrix[r][0] = 0;
for (c = 1; c < cols; c++)
{
sub = matrix[r-1][c-1] + scoreSubstitution(seq1.charAt(r),seq2.charAt(c));
ins = matrix[r][c-1] + scoreInsertion(seq2.charAt(c));
del = matrix[r-1][c] + scoreDeletion(seq1.charAt(r));
// choose the greatest
matrix[r][c] = max (ins, sub, del, 0);
if (matrix[r][c] > max_score)
{
// keep track of the maximum score
max_score = matrix[r][c];
max_row = r; max_col = c;
}
}
}
}
由於沒有意識到這是簡單的東西複雜的區域....謝謝你清除它 –
這工作,但是是一個非常低效的建立一個長字符串的方式。 –
同意。我只是在說一個觀點。這裏肯定應該使用StringBuilder。 – giorashc