编写一个函数,推断某数字是不是是回文数字。
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; }
以上就是java怎样推断一个数是不是是回文数的细致内容,更多请关注ki4网别的相干文章!