Reversing Integer Value
I cannot figure this out. This is for homework. I need to create a method that reverses an integer that is passed to it, however, I cannot get past an OutOfBoundsException. The integer that is passed into the method can be of any length. And I have to return an integer instead of an array or string. I get the exception on the `backInt[z] = x;` line. Any ideas as to why this isn't working? Here is the code that I have so far:

    public static int reverseIt(int x){
		
		int y = String.valueOf(x).length();
		int[] backInt = new int [y];
		for(int z = 0; z <= y; z++){
			x %=10;
			backInt[z] = x;
			x /= 10;
		}
    			int u = backInt[];
    			return u;
		
		
		return -1;
		
	}
Reversing Integer Value
===

I cannot figure this out. This is for homework. I need to create a method that reverses an integer that is passed to it, however, I cannot get past an OutOfBoundsException. The integer that is passed into the method can be of any length. And I have to return an integer instead of an array or string. I get the exception on the `backInt[z] = x;` line. Any ideas as to why this isn't working? Here is the code that I have so far:

    public static int reverseIt(int x){
		
		int y = String.valueOf(x).length();
		int[] backInt = new int [y];
		for(int z = 0; z <= y; z++){
			x %=10;
			backInt[z] = x;
			x /= 10;
		}
    			int u = backInt[];
    			return u;
		
		
		return -1;
		
	}