I am in Introduction to Programming using Java so I need hel
I am in Introduction to Programming using Java, so I need help writing a program in Java. Here is the exercise I am currently working in:
\"6.3 (Palindrome integer) Write the methods with the following headers
// Return the reveral 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.\"
Any help in providing me a simple and easy to understand program in Java for this exercise would be greatly appreciated.
Solution
PalindromeTest.java
import java.util.Scanner;
 public class PalindromeTest {
  
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print(\"Enter the number: \");
        int n = scan.nextInt();
        if(isPalindrome(n)){
            System.out.println(+n+\" is a palindrome\");
        }
        else{
            System.out.println(+n+\" is NOT a palindrome\");
        }
    }
    public static int reverse(int number){
        int reversenum = 0;
        while(number > 0){
            int r = number % 10;
            reversenum = reversenum * 10 + r;
            number = number / 10;
        }
        return reversenum;
    }
    public static boolean isPalindrome(int number){
        if(number == reverse(number)){
            return true;
        }
        else{
            return false;
        }
    }
 }
Output:
Enter the number: 12321
 12321 is a palindrome
Enter the number: 12322
 12322 is NOT a palindrome

