diff --git a/StockBuyAndSell.java b/StockBuyAndSell.java new file mode 100644 index 0000000..d5a2006 --- /dev/null +++ b/StockBuyAndSell.java @@ -0,0 +1,42 @@ +package DSA.Arrays; + +import java.util.Scanner; + +public class StockBuyAndSell { + static int maxProfit(int price[], int n) + { + int profit = 0; + + for(int i = 1; i < n; i++) + { + if(price[i] > price[i - 1]) + profit += price[i] - price[i -1]; + } + + return profit; + } + + + public static void main(String args[]) + { + int n; + Scanner sc=new Scanner(System.in); + + System.out.print("Enter the number of stocks: "); + + n=sc.nextInt(); + + int[] arr = new int[10]; + System.out.println("Enter stocks: "); + for(int i=0; i