【发布时间】:2011-03-30 17:17:27
【问题描述】:
我正在尝试从另一个类访问 toString 方法以打印数组的元素。
info += "Purchases:\n";
for(int index = 0; index < purchases.size(); index++){
info += "[" + (index + 1) + "] ";
info += purchases.get(index).toString();
info += "\n";
}
我希望将访问 Purchases 类中 toString 的代码打印出来
public String toString(){
String info;
DecimalFormat formatter = new DecimalFormat("$#0.00");
info= (date.get(Calendar.MONTH) +1) + "/" + date.get(Calendar.DAY_OF_MONTH) + "/" + date.get(Calendar.YEAR);
info += "\t" + vendor + "\t\t";
info += (formatter.format(amount));
return info;
}
我该怎么做?
【问题讨论】:
-
你遇到了什么错误?