我已经编写了下面的代码,现在我需要对其进行编辑,以便显示超过3000的结帐号码。即必须显示:
以下结帐时间超过3000.00磅: 结帐编号“元素编号” 结帐编号“元素编号”等
我一直在尝试一些不同的方法但尚未成功。谢谢你的帮助 !
import java.util.Scanner;
public class Checkouts
{
static final int NUMBER_OF_CHECKOUTS = 6, MAX_TAKING = 1000000;
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
double[] checkoutList = new double[NUMBER_OF_CHECKOUTS];
System.out.println();
for (int index = 0; index < checkoutList.length; index++)
{
System.out.print("\tEnter takings for checkout number ");
System.out.print((index + 1) + ": ");
checkoutList[index] = scan.nextDouble();
while (checkoutList[index] < 0 || checkoutList[index] > MAX_TAKING)
{
System.out.print("\tImpossible! - enter takings for checkout number ");
System.out.print((index + 1) + " again: ");
checkoutList[index] = scan.nextDouble();
}
}
System.out.println();
double totalTakings = 0;
for (int index = 0; index < checkoutList.length; index++)
{
totalTakings += checkoutList[index];
}
System.out.println("The total takings for the supermarket is " + totalTakings );
} }
答案 0 :(得分:1)
由于你已经有一个遍历每个索引的for循环,我们可以在那里进行检查:
du