public static void main(String args[]) {
int val =121;
int revNum = reverse(val);
if(val ==revNum) {
System.out.println("palindrom");
}else {
System.out.println("not palindrom");
}
}
static int reverse(int val) {
int revNum = 0;
while(val>0) {
int temp = val%10;
val = val/10;
revNum = revNum*10+temp;
}
return revNum;
}
}
int val =121;
int revNum = reverse(val);
if(val ==revNum) {
System.out.println("palindrom");
}else {
System.out.println("not palindrom");
}
}
static int reverse(int val) {
int revNum = 0;
while(val>0) {
int temp = val%10;
val = val/10;
revNum = revNum*10+temp;
}
return revNum;
}
}
No comments:
Post a Comment