public class Pallendrom {
public boolean isPallendrom(int num) {
int tmp = num;
int rem = 0;
int sum = 0;
while (tmp > 0) {
rem
= tmp % 10;
sum
= sum * 10 + rem;
tmp
= tmp / 10;
}
return (sum == num);
}
public static void main(String[]
args) {
int a = 12321;
Pallendrom
p = new Pallendrom();
if(p.isPallendrom(a)){
System.out.println(a + " is
Pallendrom.");
}else{
System.out.println(a + " is not
Pallendrom.");
}
}
}
No comments:
Post a Comment