Having run time error,i.e index outofbound

why im having runtym error in this code
package func;

import java.util.Scanner;

public class BubbleSort {
public static void bubble(int arr[])
{
for(int i=0;i<arr.length;i++)
{
for(int j=0;j<arr.length-i;j++)
{
if(arr[j]>arr[j+1])
{
int temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}

		}
		
		
		
	}
	
	
	
	
	
}
public static void printArray(int arr[])
    {
        int n = arr.length;
        for (int i=0; i<n; ++i)
            System.out.print(arr[i] + " ");
        System.out.println();
    }


public static void main(String[] args) {
	Scanner s=new Scanner(System.in);
 	int n=s.nextInt();
	int[] arr=new int[n];
	for(int i=0;i<n;i++)
	{
		//arr[i]=s.nextInt();
	}
	bubble(arr);
	printArray(arr);
	
	
	
		
}
	// TODO Auto-generated method stub

}

hey @missroy you are getting ArrayOutOfBound for the inner loop the condition should be arr.length - I -1 because in the loop when you will be checking if(ar[j] > ar[j+1] ) it will give error for the value of j equal to 3 since 3 + 1 = 4 will be out of bound.
so Two changes are made i) inner loop condition should ar.length -i - 1
ii)uncomment the statement in in the main method arr[I] = s.nextInt();

ya it is commented bcz i try to give input at compile tym bcz run time wasnt working

@missroy If your doubt is resolved please marked this doubt as resolved and give me a rating please.

hey @missroy hope that I was able to clear your doubt.If you still have any just reopen this doubt.
You can give me a rating according to you experience.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.