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();
    }
}// Check whether the string is a palindrome or not.
#include <bits/stdc++.h>

using namespace std;

int main(){
    string s;
    cin >> s;
    
    int l = 0;
    int h = s.length()-1;

    while(h > l){
        if(s[l++] != s[h--]){
            cout << "Not a palindrome" << endl;
            return 0;
        }
    }
    cout << "Is a palindrome" << endl;
    return 0;

}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;
	}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;
	}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 ( ͡~ ͜ʖ ͡°)function palindrome(str) {
  var re = /[\W_]/g;// representing Non-alphanumetic characters
  var lowRegStr = str.toLowerCase().replace(re, '');
  var reverseStr = lowRegStr.split('').reverse().join(''); 
  return reverseStr === lowRegStr;
}
palindrome("A man, a plan, a canal. Panama");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.");
    }
  }
}function isPalindrome(str) {
  str = str.toLowerCase();
  return str === str.split("").reverse().join("");
}<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>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;
}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;
}

Java相关代码片段

add border to pane in javafx

how to check response time using REST Assured

java home path in mac

my image is not found java fx

pom.xml JUnit 5 dependencies

java set difference

regex for first name only

StringBuffer(CharSequence seq)

array class methods in java

how to read all line from file java

Java int length

intent example in android

how to doubling size of an arrays in java

how to find my jdk path

how to handle multiple throws exception in java

spring boot jdbc for postgrest

factorial of a number

types of typecasting in java

types of assignment statement in java

Thread mutex

env files in spring boot

java over loading

logging in spring boot

how to split a list in multiple lists java

can two servlet have same urlpattern

spring debug

jsp spring

hanoi tower recursion java

java equals

age difference java

sed cheat sheet

java compare method

how to make a activity default in manifest

java max memory size

yum uninstall java

timestamp to long java

how to set background image in android studio

simple calculator in android

When to use HashMap vs Map

spring boot jpa

spring data jpa

spring jdbc

jpa vs hibernate

java with checking the password matching

profile in spring boot

string templates java

spring rest controller

java arraylist get item

com.oracle.jdbc

check if map is not empty java

how to install java 8 on debian 12

regex caractères spéciaux java

java 11 yum install

manage session in redis spring boot

java: error: release version 19 not supported

bean scope in spring

xml configuration in spring

spring cdi annotations

postconstruct and predestroy in spring

java decode_message

spring lazy initialization

java decorator design pattern

dependency injection in spring

check back pressed in fragment andorid

send email to any domain using java

record java

vs code setup for input/output in java

substring java

receive second word in string java

loose coupling in java

default value of char in java

spring boot repository pattern

spring boot h2 database

add security to spring admin

java islessthan method

Java implementation of recursive Binary Search

java round double

java downcasting

range of fibonacci series in java using recursion

java by anyone