import java.util.*; public class ex5_3 { public static int reverse(int number) {
ID: 3620440 • Letter: I
Question
import java.util.*;
public class ex5_3
{
public static int reverse(int number)
{
String temp = "" + number;
String output = "";
for(char c : temp.toCharArray())
{
output = c + output;
}
return Integer.parseInt(output);
}
public static boolean isPalindrome(int number)
{
return number == reverse(number);
}
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
System.out.print("Enter an integer: ");
int n = kb.nextInt();
System.out.println(n+" is a palindrome? "+isPalindrome(n));
}
}
Explanation / Answer
please rate - thanks #include<iostream>#include<string>
using namespace std;
bool isPalindrome( int );
int main()
{int input,copy;
bool palin;
int i;
cout<<"Enter an integer: ";
cin>>input;
palin=isPalindrome(input);
cout;
if(palin)
cout<<input<<" is a palindrome? "<<"true ";
else
cout<<input<<" is a palindrome? "<<"false ";
system("pause");
return 0;
}
bool isPalindrome( int input)
{int digit,n=0,m;
m=input;
while(m>0)
{digit=m%10;
m/=10;
n=n*10+digit;
}
return input==n;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.