我编写了以下程序以相反的顺序打印一个数字。它给了我一个 ArrayIndexOutOfBound 异常
import java.util.Scanner;
public class Ch6_26 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int x;
System.out.println("Enter the number to be reversed: ");
x = input.nextInt();
Reverse(x);
}
static void Reverse(int a){
int s[] = new int[5];
int j = 0;
int x = a;
for(int i = 1; a >= 0 ; i++){
s[i] = x % 10;
x /= 10;
j = i;
}
for(int i = 0; i <= j; i++){
System.out.printf("%d ", s[i]);
}
}
}