# Need help determining if number is a palindrome using an array!

• February 28th, 2013, 08:32 PM
jetset222
Need help determining if number is a palindrome using an array!
I have:

Code java:

``` public static void main(String[] args) { while (true) { display(check(retrieveInput())); } }   public static String retrieveInput() { Scanner scan = new Scanner(System.in); return scan.next(); }   public static boolean check(String input) { boolean check = false; try { Integer.parseInt(input); if (input.charAt(0)==input.charAt(4) && input.charAt(1)==input.charAt(3)) check = true;   } catch(Exception e) { check = false; }   return check; }   public static void display(boolean check) { if(check) System.out.println("Is a five-digit palindrome."); else System.out.println("Is not a five-digit palindrome."); } }```
but the assignment is requiring me to use an array which I don't know how to do. Please Help!
• February 28th, 2013, 09:06 PM
Norm
Re: Need help determining if number is a palindrome using an array!
Strip off each power of 10 and store that value in the array
Given 123 the array would be {1,2,3}

[code=java]
[/code]
to get highlighting and preserve formatting.
• February 28th, 2013, 09:29 PM
jetset222
Re: Need help determining if number is a palindrome using an array!
Thanks for your reply. Sorry, this is my first java course. What do you mean by stripping off each power of ten?
• February 28th, 2013, 09:38 PM
Norm
Re: Need help determining if number is a palindrome using an array!
This has nothing to do with java. Its basic math
The number 123 is 1 * 10^2 + 2 * 10^1 + 3 * 10^0

The programming part would Use the % and / operators to do the work
• February 28th, 2013, 10:05 PM
jetset222
Re: Need help determining if number is a palindrome using an array!
Thanks for the suggestions but I am not sure how to use those operators. Thanks again though.
• February 28th, 2013, 10:09 PM
Norm
Re: Need help determining if number is a palindrome using an array!
23 % 10 = 3
23 / 10 = 2