public class Palindrome {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print(“Enter a word to check whether it is a palindrome or not: “);
String word = in.nextLine();
int length = word.length();
int i, begin, end, middle;
begin = 0;
end = length – 1;
middle = (begin + end)/2;
for (i = begin; i <= middle; i++) { if (word.charAt(begin) == word.charAt(end)) { begin++; end--; } else { break; } } if (i == middle + 1) { System.out.println("This is a palindrome."); } else{ System.out.println("This is not a palindrome."); } } } public class Palindrome { public static void main(String[] args) { int number = 121; int reversedInteger = 0; int remainder = 0; int originalInteger; originalInteger = number; // reversed integer is stored in variable while (number != 0) { remainder = number % 10; reversedInteger = reversedInteger * 10 + remainder; number /= 10; } // palindrome if orignalInteger and reversedInteger are equal if (originalInteger == reversedInteger) { System.out.println(originalInteger + " is a palindrome."); } else { System.out.println(originalInteger + " is not a palindrome."); } } } import java.util.Scanner; 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.”);
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar. Sentence-length palindromes may be written when allowances are made for adjustments to capital letters, punctuation, and word dividers, such as “A man, a plan, a canal: Panama”, “Was it a car or a cat I saw?” or “No ‘x’ in Nixon”.
This program will check whether the given string is palindrome or not.
Any string with less than two characters is a palindrome.
The first character in the string should be equal to the last one.
The second character in the string should be equal to the second last one.
And so on…
If all these comparisons are true, then it is a palindrome. If any of these comparisons are false, then it is not a palindrome.
A Palindrome is a word, or phrase that reads the same forward or backward. Examples of palindromes are:
Radar, deified, and malayalam
A palindrome can be a word, number, phrase, or other sequence of characters which reads the same backward as forward. The word “palindrome” was coined from the Greek roots palin (“again”) and dromos (“way, direction”). A simple example of a palindrome is the word “racecar”, which is spelled the same way backwards and forwards.
Palindromes are words, phrases, or sequences that read the same backward as forward, e.g., madam or nurses run. A palindrome is a word, phrase, number or other sequence of units that has the property of reading the same in either direction (the adjustment of punctuation and spaces between words is generally permitted).
Tomy is a contributor at AskMeCode. We are committed to providing well-researched, accurate, and valuable content to our readers.
You May Also Like
Web Development: Essential Tools and Resources
Web Development: The Green Approach to Building Sustainable Websites In an era where environmental consciousness shapes every aspect of our...
Top 5 Fighter Planes in The World
The best fighter planes in the world are those that are ranked at the top of the list. This is...
Create a Social App for free! prismjs is your easy to use and free social chat plugin
prismjs is your easy to use and free social chat plugin: A blog about how you can use this wonderful...
Sending Files to Your Server with Code
This blog post is about how you can use git and vscode to send files from your local environment to...
