
/*
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 = "1234789";
    
    public static void main(String[] args) 
    {
        System.out.println("Welcome to Online IDE!! Happy Coding :)");
        ascending(str);
    }
    
    public static boolean ascending(String str)
    {
        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++;
        }
        else
        {
            if (!(str.length()<(2*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.

                return true;
            }
            
            else  //str.length()>0
            {
                //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;
                    
                    String blockBefore = str.substring((str.length() - (2*n)),(str.length()-n));
                    
                    if ((Long.valueOf(blockBefore))<Long.valueOf(block))
                    {
                        //this is ascending
                        //perform recursion call    ascending(“XXXXXXXXXX”);
                        //it has to set the String now so that it is one block before the blockBefore
                        int lengthBlockBefore = blockBefore.length();
                        ascending(str.substring((lengthBlockBefore-n),lengthBlockBefore));
                    }
                    
                    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(str);
                    }

                }

            
            catch (StringIndexOutOfBoundsException | ArrayIndexOutOfBoundsException e)
            {
                //Not entire sure what to include in here at the moment
                return false;
            }

            
            
        }
            
        }
        
        return false;
        
    }
    return false;
}
}
