Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How can I determine if a 5 digit number is a palindrome using an array

$
0
0
I've searched everywhere and have found lots of examples on how to tell if it is a palindrome but none showing how to do it with an array. So far I have,
 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.");



I'm not sure how to include an array in this. Any help is greatly appreciated

Viewing all articles
Browse latest Browse all 51036

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>