我已经将我的排序问题编写如下,但我遇到了一个ArrayIndexOutOfBounds
异常。我无法弄清楚。请帮忙。
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;
}
}
}