Guten Abend zusammen,
mein Palindrom will nicht wie ich will und ich sehe nicht was ich in diesem Code- Abschnitt falsch mache. Bzw. weiß ich nicht wie ich die erste for-Schleife ändern muss, damit ich keinen outOfBounce zurück bekomme.
Gruß
mein Palindrom will nicht wie ich will und ich sehe nicht was ich in diesem Code- Abschnitt falsch mache. Bzw. weiß ich nicht wie ich die erste for-Schleife ändern muss, damit ich keinen outOfBounce zurück bekomme.
Code:
public static void main(String[] args){
String string = "Ab!b.a";
String upTo = string.toUpperCase(); // given string becomes capital
char[] seaWord = upTo.toCharArray(); // creates an array from capital string
int count = 0; // counts the valid letters
int count2 = 0;
boolean result = false;
//testarea
System.out.println(upTo);
System.out.println(seaWord);
//System.out.println(count);
//System.out.println(count2);
//
for (int i = 0; i < upTo.length(); i++) {
if (seaWord[i] >= 'A' && seaWord[i] <= 'Z') {
count++;
System.out.print(seaWord[i]);
}
}
Compiler sagt:
AB!B.A
AB!B.A
ABBAException in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4
at testa.main(testa.java:41)
Gruß