Hallo Zusammen, ich weiß es nicht, wo ich den Fehler gemacht habe, ich denke mal , dass ich keine Fehler gemacht habe. Aber ich habe keine Wert true oder false zurückbekommen. Mein Programm soll die Wörter von Vorne sowie von hinten gleich lesen können, aber es passiert nicht, ich hoffe , dass jemand mir weiter helfen könntet.
Java:
import java.util.Scanner;
public class Wortisp {
public static void main(String[] arg){
Scanner scanner = new Scanner(System.in);
System.out.print("Gebe dein Wort ein: ");
String wort = scanner.next();
boolean bool = ispalindrom(wort);
}
public static boolean ispalindrom(String wort)
{
String wortteil_1 = wort.substring(0,wort.length()/2),
wortteil_2 = wort.substring(wort.length()/2,wort.length());
String wortteil_2_spiegel = "";
for(int i = wortteil_2.length() - 1; i >= 0; i--)
{
wortteil_2_spiegel += wortteil_2.charAt(i);
}
if(wortteil_1 == wortteil_2_spiegel)
return true;
else
return false;
}
}