I have written a program to print the digits of a number in reverse order. It gives me ArrayIndexOutOfBound exception
<p>I have written the following program to print a number in the reverse order.
It is giving me an ArrayIndexOutOfBound exception</p>

<pre><code>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 &gt;= 0 ; i++){
            s[i] = x % 10;
            x /= 10;
            j = i;
        }

        for(int i = 0; i &lt;= j; i++){
            System.out.printf("%d  ", s[i]);
        }
    }
}
</code></pre>
