Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How do I write a if statement to return the difference in an array?

$
0
0
For my method double lastPriceChange() if there are two or more prices in the array, it will return the difference between the last two (previous - last), if there are fewer items in the array then it should just return ZERO.

I am stuck on how I should start my if statements

 //Fields
   double lastPChange; 
   double[] dailyPrices;
   int numberOfDaysWithData;
   
 public void addTrade(double price)
 {
   dailyPrices[numberOfDaysWithData] = price;
   numberOfDaysWithData = numberOfDaysWithData + 1;
   this.numberOfDaysWithData++;
   lastPChange = (numberOfDaysWithData - 2);
 }
 
 public int numTrades()
 {
  return numberOfDaysWithData;
 }
 
 public double lastPriceChange()
 {
   return ;
 }

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>