我想知道是否有人能幫我找到一組變量的最大值並將它們賦值給另一個變量。這裏是我的代碼片段,可以幫助理解我在說什麼。如何找到變量集的最大值
// Ask for quarter values.
System.out.println("What is the value of the first quarter?");
firstQuarter = input.nextDouble();
System.out.println("What is the value of the second quarter?");
secondQuarter = input.nextDouble();
System.out.println("What is the value of the third quarter?");
thirdQuarter = input.nextDouble();
System.out.println("What is the value of the fourth quarter?");
fourthQuarter = input.nextDouble();
//Tell client the maximum value/price of the stock during the year.
//maxStock = This is where I need help
System.out.println("The maximum price of a stock share in the year is: $" + maxStock + ".");
我很抱歉,我認爲這在Java論壇或類似的東西之下。 – 2012-02-16 00:55:50
@CodyBennett不用擔心。我已經爲你添加了Java標籤。如果您正在尋找不同的答案,它可能有助於獲得更多答案。 – nybbler 2012-02-16 01:08:46
該解決方案如書面所述被打破。 Double.MIN_VALUE返回「double類型的最小正非零值」,它是一個非常接近0的數字,而不是最大可能的負雙數。相反,可以使用類似Double.NEGATIVE_INFINITY或-Double.MAX_VALUE。 – ulmangt 2014-08-22 02:23:44