I want to create an ordered array to study about complexity.I know this a very basic code. I am getting an error saying......
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
    at myWork.orderedArray.<init>(orderedArray.java:20)
    at myWork.mainClass.main(mainClass.java:6)
my code is
package myWork;
public class orderedArray {
    int j; 
    int arr[]=new int[10];
    orderedArray(int n){
        for(int i=0;i<arr.length;i++){
            arr[i]=0;
        }
        for(int i=0;i<arr.length;i++){
            if(arr[i]<=n){
                for(int j=arr.length;j>i+1;j--){
                    arr[j]=arr[j-1];
                }
                arr[i]=n;
            }
        }
    }
 void dispaly(){
     for(int i=0;i<arr.length;i++){
         System.out.println(arr[i]);
     }
 }
}
and I created an object in main class and just ran the main class which i think its not relevant to the error
package myWork;
public class mainClass {
    public static void main(String[] args) {
    orderedArray obj1= new orderedArray(5);
    }
}
Thank you for your time reading this. Please accept my apoligies if you find some minor mistakes in my English and for the way i putted the code in this question (first time in stackoverflow so i dont know how to put a question with code properly :D)
 
     
     
    