I've written my sorting problem as follows, but i am getting an ArrayIndexOutOfBounds
exception.
which i'm not able to figure it out. plz help.
System.out.println("Enter the total no of digits to sort:- ");
n = Integer.parseInt(br.readLine());
x = new int[n];
System.out.println("Enter the elements:- ");
for(i = 0; i < n; i++)
x[i] = Integer.parseInt(br.readLine());
for(i = 0; i < n; i++)
{
for(j = 0; j < n; j++)
{
if(x[j] > x[j+1]) //ascending order
{
temp = x[j];
x[j] = x[j+1];
x[j+1] = temp;
}
}
}