Write a program that reads a string and check whether it is a palindrome string or not without any string slice
Answers
Answer:
string is not a palindrome.
Explanation:
because palindrome means when we reverse also we get same spelling
Answer:
public class Palindrome
{
public static void main(String args[])
{
String a, b = "";
Scanner s = new Scanner(System.in);
System.out.print("Enter the string you want to check:");
a = s.nextLine();
int n = a.length();
for(int i = n - 1; i >= 0; i--)
{
b = b + a.charAt(i);
}
if(a.equalsIgnoreCase(b))
{
System.out.println("The string is palindrome.");
}
else
{
System.out.println("The string is not palindrome.");
}
}
}
Output:
$ javac Palindrome.java
$ java Palindrome
Enter the string you want to check:NeveroddorEVen
The string is palindrome.