xxxxxxxxxx
import java.util.*;
class Example {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.print("Enter any word : ");
String w = input.nextLine();
int len = w.length() - 1;
String nword = "";
for (int i = len; i >= 0; i--) {
nword += w.charAt(i);
}
boolean a = w.equals(nword); // Compare the original and reversed strings
System.out.println(a);
if (a) {
System.out.print("The string is a Palindrome ");
} else {
System.out.print("The string is not a Palindrome ");
}
}
}
xxxxxxxxxx
import java.util.*;
class Example {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.print("Enter any word : ");
String w = input.nextLine();
int len = w.length() - 1;
String nword = "";
for (int i = len; i >= 0; i--) {
nword += w.charAt(i);
}
boolean a = w.equals(nword); // Compare the original and reversed strings
System.out.println(a);
if (a) {
System.out.print("The string is a Palindrome ");
} else {
System.out.print("The string is not a Palindrome ");
}
}
}