交换最后两个数字,给出ArrayIndexOutOfBoundException ... 因为我是编程新手并且无法找到问题,请纠正我在哪里做错了... 提前谢谢你......
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the Number : ");
int n = scan.nextInt();
int m = n;
int size = String.valueOf(n).length();
int arr[] = new int[size];
for (int i = 0; i < size; i++) {
arr[i] = n % 10;
n = n / 10;
}
System.out.println("The next permuatation will be : ");
int temp = arr[m - 2];
arr[m - 2] = arr[m - 1];
arr[m - 1] = temp;
System.out.print(arr);
}