/**
 * 题目描述:
 * 有这样一类数字,他们顺着看和倒着看是相同的数,例如:121,656,2332等,这样的数字就称为:回文数字。编写一个函数,判断某数字是否是回文数字。
 * 要求实现方法:
 * public String isPalindrome(String strIn);
 * 【输入】strIn: 整数,以字符串表示;
 * 【返回】true: 是回文数字;
 * false: 不是回文数字;
 * 【注意】只需要完成该函数功能算法,中间不需要有任何IO的输入输出
 * @author Administrator
 *
 */
public class PalindromeNumber {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入数字:");
        String strNum = scan.next();
        boolean result = isPalindrome(strNum);
        System.out.println(result);
    }
    
    public static Boolean isPalindrome(String str){
        boolean result=false;
        for(int i=0; i<str.length()/2;i++){
            if(str.charAt(i) == str.charAt(str.length()-1-i)){
                result=true;
            }else{
                return result;
            }
        }
        return result;
    }

 

相关文章:

  • 2021-09-10
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2021-10-22
猜你喜欢
  • 2021-10-29
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2021-06-13
  • 2021-12-25
相关资源
相似解决方案