/*
Online Java - IDE, Code Editor, Compiler
Online Java is a quick and easy tool that helps you to build, compile, test your programs online.
*/
public class Main
{
    public static void main(String[] args) {
    System.out.println("Welcome to Online IDE!! Happy Coding :)");
    
    int [] stockPrices = new int[]{9,11,8,5,7,10};
    int difference=0;
    int temp=0;
    int stockBought=0;
    int stockSold=0;
    int length=stockPrices.length;
    
    for (int i=0; i<stockPrices.length;i++)
    {
        if (i==stockPrices.length-1)
        {
            length=stockPrices.length-1;
        }
        
        for (int j=0; j<length;j++)
        {
            if (j==i && j!=stockPrices.length-1)
            {
                j++;
            }
            
            if (j>i)
            {
                System.out.println("\nInitial stock price: " + stockPrices[i]);
                System.out.println("Future stock price: " + stockPrices[j]);
                difference=stockPrices[j]-stockPrices[i];
                System.out.println("Difference: " + difference);
            }
            
            if (difference>temp)
            {
                temp=difference;
                stockBought = stockPrices[i];
                stockSold = stockPrices[j];
            }
        }
    }
    
    System.out.println("\nMaximum profit: " + temp);
    System.out.println("Stock bought at: " + stockBought);
    System.out.println("Stock sold at: " + stockSold);
    }
}