Java判断回文数算法简单实现

好久没写java的代码了, 今天闲来无事写段java的代码,算是为新的一年磨磨刀,开个头,算法是Java判断回文数算法简单实现,基本思想是利用字符串对应位置比较,如果所有可能位置都满足要求,则输入的是回文数,否则不是,不多说,上代码:

import java.util.*;

public class HiJava
{
  public static void main(String[] args)
  {
   Scanner sc = new Scanner(System.in);
   System.out.println("Please input the number: ");
   String word = sc.next();
   int i = word.length();
   int j = 0;
   while (j <= (i / 2) -1 && word.charAt(j) == word.charAt(i - j - 1))
     j++;
   if (j == i / 2)
    System.out.println("Yes it is HuiWen.");
   else
    System.out.println("No it is not HuiWen.");
   
   
   sc.close();
   }

}
原文地址:https://www.cnblogs.com/pugang/p/4306238.html