134k views
3 votes
Write a method named isNumericPalindrome that accepts an integer parameter named num. If num is a palindrome the method must return true. Otherwise the method must return false. You can assume as a precondition that num has exactly 5 digits (i.e. it is between 10000 and 99999.) For example, 12321 is a palindrome while 12231 isn't because it's the same number if reversed. public boolean isNumericPalindrome(int num)

1 Answer

4 votes

Answer:

Step-by-step explanation:

The following code is written in Java. It is a method that reverses the number that is passed as an argument and compares it to its original version. Then it finally returns the results of the comparison as a boolean (either True or False). Two test cases have been created and can be seen in the attached image below.

public static boolean isNumericPalindrome(int num) {

String numString = Integer.toString(num);

String reversed = "";

for (int i = numString.length()-1; i >= 0; i--) {

reversed += numString.charAt(i);

}

return numString.equals(reversed);

}

Write a method named isNumericPalindrome that accepts an integer parameter named num-example-1
User Baadshah
by
6.8k points