   # Check if digit of a given number can be rearranged to form a palindrome?

1,291 views
Check if digit of a given number can be rearranged to form a palindrome? posted Nov 3, 2017

+1 vote

Try this code I tested in my system

`````` class Palindrome {
private static boolean canMakeAPalindrome(int number) {
int[] frequencyArr = createFrequencyArray(number);

int oddCharCount = 0;

for (int ch : frequencyArr) {

// Count characters with odd occurrence.
if (ch % 2 != 0)
oddCharCount++;

// If more than one character in the string has odd occurrence then
// palindrome cannot be formed from given string
if (oddCharCount > 1)
return false;
}

return true;
}

private static int[] createFrequencyArray(int number) {
int[] frequencyArr = new int;

char[] charArray = String.valueOf(number).toCharArray();

for (char ch : charArray)
frequencyArr[ch]++;

return frequencyArr;
}

public static void main(String[] args) {
int number=1251256;

System.out.println("Can palindrome be formed from '" + number(number));
}

}
`````` answer Nov 3, 2017
O thanks fellas
Similar Questions
+1 vote

Given a singly linked list of integers, write a function in java that returns true if the given list is palindrome, else returns false

Rohit's teacher has asked him to write a function that takes as input parameters the first parameter will be an integer number representing. The number whose digitSum needs to be found the second parameter will be a char representing the
option which would either be 'e' or 'o' representing 'even' or 'odd' respectively.

### Function signature public int digitSum(int n, char ch);

``````digitSum(9625, 'o')
Example 1: if given number is 9625 and the option is 'o' we must add only the odd digit i.e. 9+5=14
digitSum(2134, 'e')
Example 2: if given number is 2134 and the option  is 'e' we must add only the odd digit i.e. 2+4=6
``````