Java: String index out of range while checking if a number is a palindrome
<p>So, in order to check if a number is a palindrome I converted it to a string. I know there is a similar question on SO but I have already checked that solution, so any help would be appreciated.
Why do I get a <code>"Exception in thread "main" java.lang.NumberFormatException:</code> ?</p>

<p>My code is here;</p>

<pre><code>/*
(Palindrome integer) Write the methods with the following headers

// Return the reversal of an integer, i.e., reverse(456) returns 654
public static int reverse(int number)

// Return true if number is a palindrome
public static boolean isPalindrome(int number)

Use the reverse method to implement isPalindrome. A number is a palindrome
if its reversal is the same as itself. Write a test program that prompts the
user to enter an integer and reports whether the integer is a palindrome.
*/

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        System.out.println("Please enter a number");
        Scanner input = new Scanner(System.in);
        int number = input.nextInt();
        if (isPalindrome(number))
            System.out.println("The number is a palindrome");
        else
            System.out.println("The number is not a palindrome");

    }

    public static int reverse(int number) {
        String reverse = "";
        String n = number + " ";
        for (int i = n.length() - 1; i &gt;= 0; i--) {
            reverse += n.charAt(i);
        }

        return Integer.parseInt(reverse);
    }

    public static boolean isPalindrome(int number) {
        return number == reverse(number) ? true : false;
    }
}
</code></pre>