我有一个项目,我面临着我再次遇到的一个问题。打印对象并获取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
我不知道我有什么方法在实际的广告牌类来创建,所以我能得到这个打印出来。你有什么建议吗?我想知道这背后的逻辑,而不是解决这个特定问题。
你想要什么打印? –