判斷是否是迴文數字(java版)
阿新 • • 發佈:2019-01-12
//123321,678876,829928這種兩端對稱的為迴文數字
/*
採用倒轉法,將數字倒轉再來對比
*/
public class Huiwenshuzi {
public boolean isHui(int j){
if(reverse(j)==j)
{
return true;
}
return false;
}
//倒轉數字
public int reverse(int j){
int m = j;
int s = 0;
while(m!=0){
s = s*10+m%10;
m = m /10;
}
System.out.println(s);
return s;
}
public static void main(String[] args){
Huiwenshuzi huiwen = new Huiwenshuzi();
if(huiwen.isHui(123321)){
System.out.println("shihuiwen");
}
else{
System.out.println(" Not shihuiwen");
}
}
}