xxxxxxxxxx
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
System.out.print("Enter any string : ");
Scanner in = new Scanner(System.in);
String origString = in.nextLine();
String reverseString = "";
char[] characters = origString.toCharArray();
for( int i = characters.length - 1 ; i >= 0 ; i-- ) {
reverseString = reverseString + characters[i];
}
//Check palindrome string
if (origString.equals(reverseString)) {
System.out.println("String is a palindrome.");
} else {
System.out.println("String is not a palindrome.");
}
}
}
xxxxxxxxxx
const isPalindrome = (str) => {
const preprocessing_regex = /[^a-zA-Z0-9]/g,
processed_string = str.toLowerCase().replace(preprocessing_regex , ""),
integrity_check = processed_string.split("").reverse().join("");
if(processed_string === integrity_check) return true
else return false
}
//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
xxxxxxxxxx
int isPlaindrome(string S)
{
// Your code goes here
int flag =0;
int l=0;
int h=S.length()-1;
while(h>l){
if(S[l++]!=S[h--]){
return 0;
}
}
return 1;
}
xxxxxxxxxx
Input: S = "abba"Output: 1Explanation: S is a palindrome
int isPalindrome(string S)
{
string st = S;
char temp;
int i=0, j= st.length()-1;
while(j>i)
{
if(S[i] != S[j])
{
return 0;
}
i++;
j--;
}
return 1;
}
xxxxxxxxxx
#include<iostream>
using namespace std;
// A function to check if n is palindrome
int isPalindrome(int n)
{
// Find reverse of n
int rev = 0;
for (int i = n; i > 0; i /= 10)
rev = rev*10 + i%10;
// If n and rev are same, then n is palindrome
return (n==rev);
}
// prints palindrome between min and max
void countPal(int min, int max)
{
for (int i = min; i <= max; i++)
if (isPalindrome(i))
cout << i << " ";
}
// Driver program to test above function
int main()
{
countPal(100, 2000);
return 0;
}
xxxxxxxxxx
<script>
// function that check str is palindrome or not
function check_palindrome( str )
{
let j = str.length -1;
for( let i = 0 ; i < j/2 ;i++)
{
let x = str[i] ;//forward character
let y = str[j-i];//backward character
if( x != y)
{
// return false if string not match
return false;
}
}
/// return true if string is palindrome
return true;
}
//function that print output is string is palindrome
function is_palindrome( str )
{
// variable that is true if string is palindrome
let ans = check_palindrome(str);
//condition checking ans is true or not
if( ans == true )
{
console.log("passed string is palindrome ");
}
else
{
console.log("passed string not a palindrome");
}
}
// test variable
let test = "racecar";
is_palindrome(test);
</script>
xxxxxxxxxx
int main()
{
char str1[20], str2[20];
int i, j, len = 0, flag = 0;
cout << "Enter the string : ";
gets(str1);
len = strlen(str1) - 1;
for (i = len, j = 0; i >= 0 ; i--, j++)
str2[j] = str1[i];
if (strcmp(str1, str2))
flag = 1;
if (flag == 1)
cout << str1 << " is not a palindrome";
else
cout << str1 << " is a palindrome";
return 0;
}
xxxxxxxxxx
int main()
{
char str1[20], str2[20];
int i, j, len = 0, flag = 0;
cout << "Enter the string : ";
gets(str1);
len = strlen(str1) - 1;
for (i = len, j = 0; i >= 0 ; i--, j++)
str2[j] = str1[i];
if (strcmp(str1, str2))
flag = 1;
if (flag == 1)
cout << str1 << " is not a palindrome";
else
cout << str1 << " is a palindrome";
return 0;
}
xxxxxxxxxx
let word = "CivIc";
let str = word.toLowerCase();
function checkPalindrome(str) {
// find the length of the string
const len = str.length;
// loop through half of the string
for (let i = 0; i < len / 2; i++) {
// check each position
// between the first and the last character
if (str[i] !== str[len - 1 - i]) {
console.log("NOT a palindrome");
}
}
console.log("The string is a palindrome");
}
xxxxxxxxxx
import java.util.Scanner;
public class PalindromeCheck {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a string: ");
String input = scanner.nextLine();
boolean isPalindrome = true;
int length = input.length();
for (int i = 0; i < length / 2; i++) {
if (input.charAt(i) != input.charAt(length - 1 - i)) {
isPalindrome = false;
break;
}
}
if (isPalindrome) {
System.out.println("The string is a palindrome.");
} else {
System.out.println("The string is not a palindrome.");
}
scanner.close();
}
}