编写一个java程序,接受带有描述的无限双重(可变)费用记录。
控制台O / P中的平均时间列表,并累计总条目数。
这是我到目前为止的代码
public class Quizz {
public double expense;
public double totalExpenses;
public static void main(String[] args) {
Quizz expenses = new Quizz();
Scanner intScan = new Scanner(System.in);
do
{
System.out.println("Enter an expense");
expenses.expense = intScan.nextInt();
}
while (proceed);
System.out.println("done counting");
}
}
答案 0 :(得分:0)
这里的类定义相当奇怪。你真的不需要一个类,只需要一个主要的方法来做你想做的事情:
Scanner doubleScan = new Scanner(System.in);
double runningTotal = 0;
do {
System.out.print("Enter an amount (-1 to exit): ");
double expense = doubleScan.nextDouble();
if (expense != -1) runningTotal += expense;
} while (expense != -1);
System.out.println("Total: " + runningTotal);