0
我是一個初學者,並沒有試過下面的程序,它給了我重複的輸出..我必須在eclipse中手動結束程序。無法弄清楚問題所在。請指教。歡迎任何其他提示。重複輸出,必須手動結束程序
import java.util.Scanner;
public class Sales_Amount {
public static void main(String[] args) {
final double Base_Salary = 25000;
double Commission = 0;
double Total_Salary;
double X;
double Y;
Scanner input = new Scanner(System. in);
System.out.print("Enter Sales Amount: ");
double Sales = input.nextDouble();
while (Commission < 25001) {
if (Sales <= 5000); {
Total_Salary = Base_Salary + (0.08 * Sales);
System.out.print(" Total Salary for " + Sales + "worth of Sales is: " + Total_Salary);
}
if (Sales > 5000 && Sales < 10001); {
X = Sales - 5000;
Total_Salary = Base_Salary + (0.08 * 5000) + (0.10 * X);
System.out.print(" Total Salary for " + Sales + "worth of Sales is: " + Total_Salary);
}
if (Sales > 10001); {
Y = Sales - 10000;
Total_Salary = Base_Salary + (.08 * 5000) + (.10 * 10000) + (.12 * Y);
System.out.print(" Total Salary for " + Sales + "worth of Sales is: " + Total_Salary);
}
}
}
}
我已經格式化您的代碼的可讀性,因爲張貼您的代碼格式是可怕的。將來我強烈建議你自己做。格式化是非常重要的,因爲如果你的代碼不是標準的可接受格式,它的可讀性不好,如果它不可讀,這是不可理解的。 –
你永遠不會在任何地方增加佣金,它仍然在0,所以while循環永遠不會結束。另外,如果你不知道格式化,按Ctrl + a,然後按Ctrl + i,應該將所有代碼格式化爲ecplise格式。 –
您的佣金永不改變。它(零)總是小於25001.因此,永遠! –