Zastanawiałem się, czy ktoś mógłby mi pomóc znaleźć maksymalną wartość zestawu zmiennych i przypisać je do innej zmiennej. Oto fragment kodu, który może pomóc w zrozumieniu tego, o czym mówię.Jak znaleźć maksymalną wartość zestawu zmiennych?
// 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 + ".");
przepraszam myślałem, że to był pod forum Java lub coś podobnego. –
@CodyBennett Bez obaw. Dodałem tag Java dla ciebie.Może pomóc uzyskać więcej odpowiedzi, jeśli szukasz innej odpowiedzi. – nybbler
To rozwiązanie jest zepsute, jak zostało napisane. Double.MIN_VALUE zwraca "najmniejszą dodatnią niezerową wartość typu double", która jest liczbą bardzo zbliżoną do 0, NIE największą możliwą ujemną podwójną. Zamiast tego można użyć czegoś takiego jak Double.NEGATIVE_INFINITY lub -Double.MAX_VALUE. – ulmangt