In Java, you can use Math.max like this:
double maxStock = Math.max( firstQuarter, Math.max( secondQuarter, Math.max( thirdQuarter, fourthQuarter ) ) );
Not the most elegant, but it will work.
Alternatively, for a more robust solution define the following function:
private double findMax(double... vals) {
double max = Double.NEGATIVE_INFINITY;
for (double d : vals) {
if (d > max) max = d;
}
return max;
}
Which you can then call by:
double maxStock = findMax(firstQuarter, secondQuarter, thirdQuarter, fourthQuarter);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…