要求:
1.如何显示每个月的存储数据,而无需为DisplayMonthData()方法多次复制和粘贴代码?
2.我的代码是否在DisplayMonthData()中总结每个月的所有值?
提前致谢。
static void MonthData()
{
try{
for(int i=0;i<10;i++){
System.out.print("Enter item "+(i+1)+" <Press ENTER to exit> : ");
monthItems[m][i] = input.next();
if (monthItems[m][i].length() == 0){
return;
} else {
System.out.print("Enter amount : $");
amount[m][i] = input.nextDouble();
System.out.println("");
}
}
}catch(Exception e){
System.out.println("");
}
}
static void DisplayMonthData()
{
if(months[m]=="Jan"){
for(int row=1;row<amount.length;row++){
for(int column=0;column<amount[row].length;column++){
//janItems[]+=monthItems[1][0];
if(amount[row][column]!=0){
System.out.println(monthItems[row][column]+"\t$"+fmt.format(amount[row][column]));
}else{}
}
}
sum[L]+=amount[1][0];
System.out.println();
System.out.println("Total amount spent for the month of January is $"+fmt.format(sum[L]));
L++;
}
}
答案 0 :(得分:0)
.equals
来比较字符串,而不是==
)