
/*
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
{
    static int n=1;
    final static String str = "123456789";
    final static String strBackup=str;
    
    public static void main(String[] args) 
    {
        System.out.println("Welcome to Online IDE!! Happy Coding :)");
        ascending(str);
    }
    
    public static boolean ascending(String str)
    {
        String blockBefore;
        System.out.println("This is the block size: " + n);
        
        if(!(str.length()%n==0))
        {
            
            //It appears that first area to check would be to perform  Str.length()%n ==0  within
            //ascending(“XXXXXXXXXX”)
            //This will ensure that the divided block is viable.
            //Otherwise perform  n=n+1   and   ascending(“XXXXXXXXXX”)
            
            n++;
            System.out.println("Value of block size has been increased to: " + n);
        }
        
        else   //str.length()%n===0   // there are discrete number of blocks based on block size n
        {
            //it can only perform operation if there are minimum two blocks in the str
            if (!(str.length()<(2*n)))
            {
                System.out.println("There are minimum of two blocks of size: " + n);
                //unsure if this can cause ArrayIndexOutOfBoundsException
                //or StringIndexOutOfBoundsException
                //most likely it can not unless there are not two instances of the the block size
            //if ( (Long.valueOf(str.substring(0,n))) <(Long.valueOf(str.substring(n,(2*n)))))
            //{
                
            //Can attempt to deduce if it is consecutive ascending numbers.
            //It is consecutive ascending order numbers since it would have processed all the 
            //blocks in question.
            
            //System.out.println(str + " with block size " + "("+n+")" + " has all ascending numbers");

                //return true;
            //}
            
            //else
            //{
                //it will perform str.substring(str.length()-n, str.length())  to get the last block
                //store in variable String block;
                
                String block = str.substring(str.length()-n, str.length());
                
                try
                {
                    //it will perform str.substring(str.length()- (2xn),     
                    //str.length()-n) to get the block before last of size n
                    //store in variable String blockBefore;
                    
                    blockBefore = str.substring((str.length() - (2*n)),(str.length()-n));
                    
                    System.out.println("This is block: " + block);
                    System.out.println("This is block before: " + blockBefore);
                    
                    //we know that its still ascending from left to right
                    if ((Long.valueOf(blockBefore))<Long.valueOf(block))
                    {
                        //this is ascending
                        //perform recursion call    ascending(“XXXXXXXXXX”);
                        //it has to set the String now so that end of the str is one block before the blockBefore
                        //so if it has compared block with blockBefore of width n
                        //this is 2n
                        //(str.length - 2n) will become the new exclusion
                        //the start position will be str.length() - (3 *n)
                        
                        //int lengthBlockBefore = blockBefore.length();
                        //System.out.println("Now to examine: ")
                        ascending(str.substring((str.length()-(3*n)),(str.length()-(2*n))));
                    }
                    
                    else
                    {
                        //block is descending
                        //this would also perform recursion call
                        //But this time we have to increase the size of the width of the integers  n=n+1;
                        //and restore str to original to start again
                        
                        n=n+1;
                        ascending(strBackup);
                    }

                }

            
            catch (StringIndexOutOfBoundsException | ArrayIndexOutOfBoundsException e)
            {
                //Not entire sure what to include in here at the moment
                return false;
            }
        }
            
        }
        
        System.out.println(strBackup + " does not consist of ascending number in any block size(n)");
        return false;
        
    }
}
