Determine whether an integer is a palindrome. do this without extra space.
Answers
Answered by
0
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int temp=a;
int place=-1;
while(temp>0){
place++;
temp/=10;
}
temp=a;
int reverse_number=0;
do{
int x=temp%10;
reverse_number+=(x*(int)Math.pow(10, place));
temp/=10;
place--;
}while(temp>0);
if(reverse_number==a)
System.out.println(a +" is a palindromic number ");
else{
System.out.println(a +" is not a palindromic number ");}
}
}
Similar questions
Psychology,
7 months ago
Math,
7 months ago
English,
7 months ago
Math,
1 year ago
English,
1 year ago