A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction.
To check whether a word is a palindrome I get the char array of the word and compare the chars. I tested it and it seems to work. However I want to know if it is right or if there is something to improve.
Here is my code:
public class Aufg1 { public static void main(String[] args) { String wort = "reliefpfpfeiller"; char[] warray = wort.toCharArray(); System.out.println(istPalindrom(warray)); } public static boolean istPalindrom(char[] wort){ boolean palindrom = false; if(wort.length%2 == 0){ for(int i = 0; i < wort.length/2-1; i++){ if(wort[i] != wort[wort.length-i-1]){ return false; }else{ palindrom = true; } } }else{ for(int i = 0; i < (wort.length-1)/2-1; i++){ if(wort[i] != wort[wort.length-i-1]){ return false; }else{ palindrom = true; } } } return palindrom; } }