
program to verify palindrome?

Program to check Sting Palindrome:
import java.util.*;
public class CheckPalindrome{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.print("Enter String: ");
String st=input.next();
String str[]=st.split("");
String reversedSt="";
for(int i=str.length-1;i>=0;i--){
reversedSt+=str[i];
}
if(st.equalsIgnoreCase(reversedSt)){
System.out.println("String is palindrome");
}
else{
System.out.println("String is not palindrome");
}
}
}
Program to check Number Palindrome:
import java.util.*;
public class NumberPalindrome {
public static void main(String[] args) {
try {
Scanner input = new Scanner(System.in);
System.out.print("Enter number: ");
int num = input.nextInt();
int n = num;
int reversedNumber = 0;
for (int i = 0; i <= num; i++) {
int r = num % 10;
num = num / 10;
reversedNumber = reversedNumber * 10 + r;
i = 0;
}
if (n == reversedNumber) {
System.out.print("Number is palindrome!");
} else {
System.out.println("Number is not palindrome!");
}
} catch (Exception e) {
System.out.println(e);
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.