Java Program to check whether number is Palindrome or not | Java Find Palindrome Number
Java program to remove duplicate elements from an array
Java program to check if a number is Armstrong : Find Armstrong Number In Java
Java program to check prime number : find prime number in Java
Indexed DB In JavaScript In Hindi | JS Indexed DB In Hindi
PHP stdClass In Hindi | stdClass In PHP
Toastr – Simple jQuery Toast Notifications | JS Toastr Example
async - await In JavaScript In Hindi | JS async - await In Hindi
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
Image on pixabay
palindrome string / words वो words होते हैं जिन्हे किसी भी side से read करने पर same ही रहते हैं। या कह सकते हैं कि अगर आप string के letters को reverse कर दें तो same ही रहेंगे।
इस article में Java language में हम palindrome string check करने के लिए एक program बनाएंगे।
// import package.
import java.util.*;
public class PalindromeExample {
// define function to check Palindrome string
public static boolean isPalindrome(String str) {
int n = str.length();
for (int i = 0; i < n / 2; i++) {
if (str.charAt(i) != str.charAt(n-i-1)) {
return false;
}
}
return true;
}
public static void main(String[] args) {
//System.in is a standard input stream
Scanner sc= new Scanner(System.in);
System.out.print("Enter a string: ");
String str= sc.nextLine();
if (isPalindrome(str)) {
System.out.println(str + " is a palindrome");
} else {
System.out.println(str + " is not a palindrome");
}
}
}
Output :
Enter a string: hello hello is not a palindrome Enter a string: level level is a palindrome
Loading ...
Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.
Get connected with me. :) LinkedIn Twitter Instagram Facebook