/*
Online Java - IDE, Code Editor, Compiler
Online Java is a quick and easy tool that helps you to build, compile, test your programs online.
*/

import java.util.*;

public class Main
{
    //TEST CASES*********************************************************************8
    //static int []nums = new int[]{100,4,200,1,2,6,7,8,9,100,101,102,103};
    //static int []nums = new int[]{100,4};
    static int []nums = new int[]{100,4,200,1,3,2};
    //static int []nums = new int[]{1,1,1,1,1,1};
    //static int []nums = new int[]{100,4,200,1,0,3,2};
    
    static int[][] Store = new int[nums.length][nums.length];
    static String [] temp = new String[nums.length];
    static int differenceCheck;
    static int count=0;
    static int firstNum;
    static int nextNum;
    
    public static boolean nextnumbercheck(int firstNum)
    {
        for (int i=0; i<nums.length; i++)
        {
            if (nextNum==nums[i])
            {
                count++;
                Store[firstNum][count]=nextNum;
                return true;
            }
        }
        count=0;
        return false;
    } //end of method
    
    public static void main(String[] args) 
    {
        System.out.println("Welcome to Online IDE!! Happy Coding :)");
        boolean nextnumberconsecutive=false;
        
        for (int i=0; i< nums.length; i++)
        {
            Store[i][count]=nums[i];
            System.out.println("\nThis is the number being checked: " + nums[i]);
            differenceCheck=1;
            
            for (int j=0; j<nums.length; j++)
            {
                if (j==i) 
                {
                    j++;
                }
                if (j!=nums.length)
                {
                    if (nums[j]==nums[i]+differenceCheck)
                    {
                        count++;  
                        do
                        {
                            System.out.println("Next consecutive number has appeared: " + (nums[i]+differenceCheck));
                            Store[i][count]= nums[i]+differenceCheck;
                            differenceCheck++;
                            nextNum = nums[i]+differenceCheck;  //next consecutive number expected....
                            nextnumberconsecutive = nextnumbercheck(i);
                        }while(nextnumberconsecutive);
                        
                    }
                }
            }  //end of inner for loop
        }  //end of for loop going through all nums
   
        System.out.println("\n\nLength of store: " + Store.length);
        System.out.println("********These are all entries*********");
        
        for (int max[]: Store)   
        {
            System.out.println(Arrays.toString(max));
        }
        
        StringJoiner sj = new StringJoiner(",");
        int currentMaximumConsectiveNumbers=0;
        String numtoString;
        boolean conditionOnce=false;
        int currentI=0;
        int j=0;
        int zeroFoundLocation=0;
        boolean zeroFound=false;
        int posZero=0;
        int oldConsecutiveNumbers=0;
        String backupStringJoiner;
        
        for (int i=0; i<Store.length; i++)
        {
            System.out.println("\n******NEW NUMBER*****:  " + Arrays.toString(Store[i]));
            System.out.println("This is current highest consecutiveNumbers: " + currentMaximumConsectiveNumbers);
            sj=new StringJoiner(",");
            
            for (j=0; j<Store[0].length; j++)
            {
                numtoString=Integer.toString(Store[i][j]);
                zeroFound=false;
                conditionOnce=true;
                backupStringJoiner = sj.toString();
                sj.add(numtoString);
        
                if (Store[i][j]==0 && j!=0)
                {
                    System.out.println("Zero found at index: " + j);
                    sj=new StringJoiner(",");
                    sj.add(backupStringJoiner);
                    posZero=j;
                    
                    if (j>zeroFoundLocation)
                    {
                        zeroFoundLocation=j;
                    }
                    zeroFound=true;
                    j=nums.length;
                    
                    if (conditionOnce)
                    {
                        oldConsecutiveNumbers = currentMaximumConsectiveNumbers;
                        currentMaximumConsectiveNumbers=zeroFoundLocation;
                        conditionOnce=false;
                    }
                }
                
                if (zeroFoundLocation>oldConsecutiveNumbers &&zeroFound)
                {
                    System.out.println("This is current highest streak of consecutiveNumbers: " + oldConsecutiveNumbers);
                    System.out.println("This is newly identified streak of consecutive Numbers: " + zeroFoundLocation);
                    temp = new String[nums.length];
                    temp[0]=sj.toString();
                    System.out.println("Highest consecutive number sequence so far: " + temp[0]);
                    break;
                }
                
                if (posZero==currentMaximumConsectiveNumbers && zeroFound)
                {
                    System.out.println("The following: " + sj.toString() + "      has been stored. \nIt is also equal to current maximum sequence of consecutive numbers: " + currentMaximumConsectiveNumbers);
                    temp[i]=sj.toString();
                    break;
                }
            }//end of for
        }//end of for
        System.out.println("\n\n****************************");
        System.out.println("Longest consecutive sequence: " + currentMaximumConsectiveNumbers);
        System.out.println("****************************");
         
        for (String s: temp)
        {
             if (s!=null)
             {
                 System.out.println(s);
             }
        }
    }//end of main
}//end of class

