我的任务要求我获得 8 周的销售额,获得最高周销售额和最低周销售额。虽然我不知道如何获得最低的一周和价值。我对 Java 很陌生
这是我的代码:
public static void main(String[] args) {
int totalSales = 0;
int averageSales = 0;
int highestSale = 0;
int highestWeek = 0;
int lowestSale = 0;
int lowestWeek = 0;
for(int i = 0; i < 8; i++) {
int s = Integer.parseInt(JOptionPane.showInputDialog("Week " + (i+1) + ":"));
totalSales += s;
if(s > highestSale) {
highestSale = s;
highestWeek = i + 1;
}
if(lowestSale < s) {
lowestSale = s;
lowestWeek = i + 1;
}
}
averageSales += totalSales / 8;
String msg = "Total sales: £" + totalSales + "\n";
msg += "Average sales: £" + averageSales + "\n";
msg += "Highest week was " + highestWeek + ", sold £" + highestSale + "\n";
msg += "Lowest week was " + lowestWeek + ", sold £" + lowestSale;
JOptionPane.showMessageDialog(null, msg);
}