【程序25】题目:一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。

Java代码
  1. import java.util.Scanner;
  2. public class Ex25 {
  3. static int[] a = new int[5];
  4. static int[] b = new int[5];
  5. public static void main(String[] args) {
  6. boolean is =false;
  7. Scanner s = new Scanner(System.in);
  8. long l = s.nextLong();
  9. if (l > 99999 || l < 10000) {
  10. System.out.println("Input error, please input again!");
  11. l = s.nextLong();
  12. }
  13. for (int i = 4; i >= 0; i--) {
  14. a[i] = (int) (l / (long) Math.pow(10, i));
  15. l =(l % ( long) Math.pow(10, i));
  16. }
  17. System.out.println();
  18. for (int i=0,j=0; i<5; i++, j++) {
  19. b[j] = a[i];
  20. }
  21. for(int i=0,j=4; i<5; i++, j--) {
  22. if(a[i] != b[j]) {
  23. is = false; break;
  24. } else {
  25. is = true;
  26. }
  27. }
  28. if(is == false) {
  29. System.out.println("is not a Palindrom!");
  30. } else if(is == true) {
  31. System.out.println("is a Palindrom!");
  32. }
  33. }
  34. }