Advertisement
Guest User

DailyBuySellSelect

a guest
Sep 18th, 2014
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.29 KB | None | 0 0
  1. double[] prices = ... // your prices
  2.  
  3. int buy = 0; // index of 'buy' price
  4. int sell = 0; // index 'sell' price
  5.  
  6. for(int i=0;i<prices.length;i++){
  7.   if(prices[i]-prices[buy] > prices[sell] - prices[buy])
  8.     sell = i;
  9.   else if( prices[i] < prices[buy] ){
  10.    buy = i;
  11.    sell = i;
  12.   }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement