package co.com.psl.programmingchallenge;

public class PslProgramingChallenge2 {
  public static void main(double[] args) {
    System.out.println(calculateProfitability(args));
  }

  /**
   * Calculates the total profitability of the given array of prices. <br>
   * Prof = sales - purchases. 
   * @param prices
   * @return total profitability.
   */
  public static double calculateProfitability(double[] prices) {
    double profitability = 0;
    double actualProf = 0;
    for (int i = 0; i < prices.length; i++) {
      for (int j = i + 1; j < prices.length; j++) {
        actualProf = prices[j] - prices[i];
        if (actualProf > profitability) {
          profitability += actualProf;
        }
      }
    }


    return profitability;
  }
}

@@ -482,24 +482,51 @@
 lProf = 0;%0D%0A
+    double totalProf = 0;%0D%0A
     for (int
@@ -757,24 +757,58 @@
 %7D%0D%0A      %7D%0D%0A
+      totalProf = profitability;%0D%0A
     %7D%0D%0A%0D%0A%0D%0A 
@@ -817,29 +817,25 @@
  return 
-profitability
+totalProf
 ;%0D%0A  %7D%0D%0A

Refactor variables