Tired after work and over thought it, then oh is that it.
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
//String inputValues = "19.35 19.30 18.88 18.93 18.95 19.03 19.00 18.97 18.97 18.98";
String inputValues = "9.20 8.03 10.02 8.08 8.14 8.10 8.31 8.28 8.35 8.34 8.39 8.45 8.38 8.38 8.32 8.36 8.28 8.28 8.38 8.48 8.49 8.54 8.73 8.72 8.76 8.74 8.87 8.82 8.81 8.82 8.85 8.85 8.86 8.63 8.70 8.68 8.72 8.77 8.69 8.65 8.70 8.98 8.98 8.87 8.71 9.17 9.34 9.28 8.98 9.02 9.16 9.15 9.07 9.14 9.13 9.10 9.16 9.06 9.10 9.15 9.11 8.72 8.86 8.83 8.70 8.69 8.73 8.73 8.67 8.70 8.69 8.81 8.82 8.83 8.91 8.80 8.97 8.86 8.81 8.87 8.82 8.78 8.82 8.77 8.54 8.32 8.33 8.32 8.51 8.53 8.52 8.41 8.55 8.31 8.38 8.34 8.34 8.19 8.17 8.16";
String[] splitValues = inputValues.split(" ");
System.out.println(Arrays.toString(splitValues));
double[] stockTrades = new double[splitValues.length];
for (int i = 0; i < splitValues.length; i++) {
stockTrades[i] = Double.parseDouble(splitValues[i]);
}
double maxDiff = Double.MIN_VALUE, fValue = 0, lValue = 0;
for (int i = 0; i < stockTrades.length; i++) {
for (int j = i+2; j < stockTrades.length; j++) {
if ((stockTrades[j] - stockTrades[i]) > maxDiff) {
fValue = stockTrades[i];
lValue = stockTrades[j];
maxDiff = lValue - fValue;
}
}
}
System.out.println(fValue + " " + lValue);
}
}
Also properly broke my lego picture maker, thank you version control! :D I did learn that with git you can check out a commit, so when I tried to commit it back to the branch, head was detached, easy way to fix. Create branch, check out new branch, commit changes, merge branches and done.
No comments:
Post a Comment