Hi I'm busy writing a program that checks (within terminal) if your input is a palindrome (sorry the Variabels are in Dutch) but the problem I have come on is even though I got the String reversed and in an if function when the input should match the reversed input (example: poop) but it still tells me instead: Nee, probeer opnieuw of ga naar huis(translation:No, try again or go home). Now I am home and how do I fix it that it gives accurate results?
Also I need to build a table out of arrays counting the a's showing their value, count b's... etc. until 9 and space could you maybe give me a push in the right direction for this too? (Not needed though really would like to know whats wrong with my function) public static void main (String[] args) {
String ui = ""; //ui = User Invoer
String palin = "";
String temp = "";
String answer = "";
int uiLength;
int klinkers = 0;
int woorden = 0;
int palinLength;
boolean zoektWoord= true;
Scanner sui= new Scanner(System.in);
System.out.println("Voer een (echte) zin in:");
ui = sui.nextLine().trim();
uiLength = ui.length();
temp=ui.replaceAll( "[^A-Z a-z 0-9]", "");
for (int q = 0; q< temp.length(); q++)
{
char aChar = temp.charAt(q);
if (65 <= aChar && aChar<=90)
{
aChar = (char)( (aChar + 32) );
}
palin+=aChar;
}
for (int qw=0; qw<palin.length(); qw++)
{
if (palin.charAt(qw) == 'a'||
palin.charAt(qw) == 'e'||
palin.charAt(qw) == 'o'||
palin.charAt(qw) == 'i'||
palin.charAt(qw) == 'u')
klinkers ++;
}
for (int x=0; x<palin.length(); x++)
{
if (palin.charAt(x) == ' ')
{
zoektWoord=true;
}
else{
if(zoektWoord) woorden++;
zoektWoord = false;
}
}
String nilap = new StringBuilder(palin).reverse().toString();
/*Als palin PRECIES gelijk is aan het omgekeerde DAN is het een palindroom*/
if (palin==nilap)
{
answer="Jazeker, op de letter";
}
else
{
answer="Nee, probeer opnieuw of ga naar huis";
}
palinLength = palin.length();
System.out.println("Lengte ongefilterde zin: " + uiLength + " karakters" );
System.out.println("Gefilterde zin:\n" + palin );
System.out.println("Lengte gefilterde zin: " + palinLength + " karakters" );
System.out.println("Aantal 'woorden': \t" + woorden );
System.out.println("Aantal klinkers:\t" + klinkers );
System.out.println("Palindroom?\t" + answer );
}
}