zoukankan      html  css  js  c++  java
  • Java-判断是否为回文数

    /**
     * @ClassName:  IsPalindrome   
     * @author: bilaisheng
     * @date: 2017年9月19日 下午2:54:08   
     * 判断是否为回文数
     * true: 是回文  false : 不是回文
     */
    public class IsPalindrome {
    
        public static void main(String[] args) {
            boolean flag = isPalindrome(1000021);
            System.out.println(flag);
        }
    
       public static boolean isPalindrome(int x) {
    
           boolean flag = false;
           String str = String.valueOf(x);
           // 此处转换.留坑.误踩
           StringBuilder restr = new StringBuilder(str).reverse();
    
           int count = 0;
           for (int i = 0; i < str.length(); i++) {
               if (str.charAt(i) == restr.charAt(i)) {
                   count++;
               }
           }
           if (count == str.length()) {
               flag = true;
           }
           return flag;
       }
    }
    
  • 相关阅读:
    stty
    ping
    read
    echo
    grep
    date
    vi与vim编辑器使用
    rename
    netstat
    input输入框的背景图片也可以这样玩
  • 原文地址:https://www.cnblogs.com/bilaisheng/p/10210958.html
Copyright © 2011-2022 走看看