I am trying to make a program that says if the introduced phrase or word is capicua, that is to say holaloh. What I do is two for, which starts to run from the beginning and the other from the end, and then save them with the charAt and the position of the index but I do well in some words and not in others. I do not know if there's something wrong with the code.
import java.util.Scanner;
public class capicua {
public static void main(String args[]) {
Scanner teclado = new Scanner(System.in);
System.out.println("Escriba una cadena.");
String x = teclado.nextLine();
int s = x.length();
int z = s / 2;
char k;
char m;
for (int i = 0; i <= z; i++) {
for (int j = (s - 1); j>z ; j--) {
k = x.charAt(i);
m = x.charAt(j);
if (k==m) {
System.out.println("Bien.");
}
}
}
}
}