Java judge palindrome sample share
- 2020-04-01 03:12:17
- OfStack
Judge a number is not palindrome number example, palindrome number is the original number and the number after the inversion is equal to, such as: 123321, to the later is still 123321, namely palindrome number
Title: a five-digit number, determine if it is palindrome. So 12321 is a palindrome, the ones place is the same as the tens place, the tens place is the same as the thousands place.
public class HuiWenShu
{
public boolean isHuiWenShu(int num)
{
int s = 0;
int bNum = num;
int mod;
//Here's how to invert the values
while(bNum != 0)
{
mod = bNum%10; //123%10 = 3
s = s*10 + mod; //s = 0*10+3
bNum = bNum/10; //BNum = 123/10=12(int automatic conversion)
}
boolean b = (s == num);
return b;
}
public static void main(String[] args)
{
HuiWenShu p = new HuiWenShu();
boolean b = p.isHuiWenShu(123321);
System.out.println(b);
}
}