Palindrome number and string

A palindrome is a word that has the same meaning when read backwards as when read from the front. Examples of palindromes are: Anna, madam, level, racecar and many more.
Mathematics also knows palindromes. Here we talk about palindromes if the numbers do not change when the sequence of numbers is reversed, for example 22 or 141.

Check Palindrome number

import java.util.Scanner;

public class PalindromeNumber {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int x, temp, r, rev = 0;
        System.out.println("Enter number to check palindrome or not: ");
        x = scan.nextInt();
        temp = x;

        scan.close();

        while (x != 0) {
            r = x % 10;
            rev = rev * 10 + r;
            x = x / 10;
        }

        if (temp == rev) {
            System.out.println(temp + " is palindrome number");
        } else {
            System.out.println(temp + " is not palindrome number");
        }
    }
}
Output
Enter number to check palindrome or not: 262
262 is palindrome number

Enter number to check palindrome or not: 13
13 is not palindrome number

Check Palindrome number or string

import java.util.Scanner;

public class PalindromeString {
    public static void main(String[] args) {
        String str, reverse = "";
        Scanner scan = new Scanner(System.in);

        System.out.println("Enter a string or number to check palindrome number: ");
        str = scan.nextLine();
        int length = str.length();

        scan.close();

        for (int i = length - 1; i >= 0; i--) {
            reverse = reverse + str.charAt(i);
        }

        if (str.equals(reverse)) {
            System.out.println(str + " is a palindrome.");
        } else {
            System.out.println(str + "isn't a palindrome.");
        }
    }
}
Output
Enter a string or number to check palindrome number: 
madam
madam is a palindrome.