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 whether number is Palindrome or not | Java Find Palindrome Number
Java program to check prime number : find prime number in Java
What is DNS In Hindi ? DNS kya hai?
PHP stdClass In Hindi | stdClass In PHP
PHP Null Coalescing Operator In Hindi , Null Coalescing Operator kya hai ?
Logical Operators In JavaScript In Hindi | JS Logical Operators 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.
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 ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook