我有一個項目,我面臨着我再次遇到的一個問題。打印對象並獲取Java中的具體內容
我們給出了這個測試儀文件。不應該編輯它。 我希望你把重點放在這一行:
System.out.println(bb) ;
它打印的對象吧?
import java.util.Arrays ;
/**
Presents some problems to the BillBoard class.
*/
public class BillboardTester
{
public static void main(String[] args)
{
int[] profits = new int[]{1, 2, 3, 1, 6, 10} ;
int k = 2 ;
System.out.println("Profits: " +
Arrays.toString(profits) + " k = " + k) ;
Billboard bb = new Billboard(profits, k) ;
System.out.println("Maximum Profit = " + bb.maximumProfit()) ;
System.out.println(bb) ;
k = 3 ;
profits = new int[]{7, 4, 5, 6, 1, 7, 8, 9, 2, 5} ;
System.out.println("Profits: " +
Arrays.toString(profits) + " k = " + k) ;
bb = new Billboard(profits, k) ;
System.out.println("Maximum Profit = " + bb.maximumProfit()) ;
System.out.println(bb) ;
}
}
然後通過打印對象,他希望這樣的結果:
Billboards removed (profit): 3(1) 0(1) => profit loss of 2
total value of billboards = 23
remaining maximum profit = 21
我不知道我有什麼方法在實際的廣告牌類來創建,所以我能得到這個打印出來。你有什麼建議嗎?我想知道這背後的邏輯,而不是解決這個特定問題。
你想要什麼打印? –