我想創建一個toString方法,它會返回我的對象「Individual」的字符串表示形式。個體是一個整數數組。該字符串應包含我的排列的介紹,以及數組的索引和元素。初始化一個int數組元素的字符串
所以理想的字符串應該是這樣的
public String toString() {
System.out.println ("The permutation of this Individual is the following: ");
for (int i=0; i<size; i++){
System.out.print (" " + i);
}
System.out.println();
for (int i=0; i<size; i++) {
System.out.print (" " + individual[i]);
}
System.out.println ("Where the top row indicates column of queen, and bottom indicates row of queen");
}
我卡在如何存儲和格式化這個特定的String表示形式,特別是對如何存儲元素的數組到字符串。
什麼是'individual'?顯示代碼。 – 2015-02-08 17:55:43
你可以包括輸入和預期輸出的例子嗎? – Pshemo 2015-02-08 17:57:41
所以你需要一個索引字符串,並在它下面有一個int值的字符串,問題是要對齊它們嗎? – 2015-02-08 17:58:57