I was wondering if anyone could help me find the maximum value of a set of variables and assign them to another variable. Here is a snippet of my code that may help with understanding what I am talking about.
// 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 + ".");
If you are given the formula y = ax2 + bx + c, then you can find the maximum value using the formula max = c - (b2 / 4a). If you have the equation y = a(x-h)2 + k and the a term is negative, then the maximum value is k.
The maximum and minimum also make an appearance alongside the first, second, and third quartiles in the composition of values comprising the five number summary for a data set. The minimum is the first number listed as it is the lowest, and the maximum is the last number listed because it is the highest.
Maxima/minima occur when f (x) = 0. x = a is a maximum if f (a) = 0 and f (a) < 0; • x = a is a minimum if f (a) = 0 and f (a) > 0; A point where f (a) = 0 and f (a) = 0 is called a point of inflection.
I believe now in Java 8 the most concise version would look like this:
DoubleStream.of(firstQuarter , secondQuarter , thirdQuarter , fourtQuarter).max();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With