Moin, ich habe eine Methode geschrieben, soweit auch alles perfekt allerdings möchte ich einen bestimmten Wert am Ende returnen, nur kommt da völliger Quatsch raus. Wenn ich das printe dann passt alles aber ausgeben tut er immer die Anzahl an characters die ich ihm übergebe... Völlig egal was ich returne. Sollte für jemandem mit Blick dafür nicht allzu komliziert sein.
Vielen Dank und VG
Vielen Dank und VG
Java:
public int suche(char[] text) throws Exception {
// String pattern = "(ab)*k?d";
int status = 1;
int c = 0;
int StVrk = 1;
boolean arraycontainsd = false;
for (int j = 0; j < text.length; j++) {
if (text[j] == 'd')
arraycontainsd = true;
}
if (arraycontainsd == false)
throw new IllegalArgumentException("d ist nicht im Muster enthalten !");
for (int ind = 0; status != 3; ind++) {
c++;
if (status == 1) {
if (text[ind] == 'd')
status = 3;
else if (text[ind] == 'a')
status = 2;
else if ((text[ind] == 'b' || (text[ind] == 'c')))
status = 1;
}
else if (status == 2) {
if (text[ind] == 'd')
status = 3;
else if (text[ind] == 'b' || text[ind] == 'c')
status = 1;
else if (text[ind] == 'a')
status = 2;
else
status = 1;
}
}
System.out.println(c);
if ((c == 2 || c == 3) && text[c - 2] == 'c') {
StVrk = 2;
System.out.println("Checkpoint0");
} else if (c == 3 && text[c - 2] == 'b' && text[c - 3] == 'a')
StVrk = 3;
else if (c == 4 && text[c - 2] == 'c' && text[c - 3] == 'b' && text[c - 4] == 'a')
StVrk = 4;
else if (text[c - 2] == 'c') {
StVrk++;
System.out.println("Checkpoint");
if (text[c - 4] == 'a' && text[c - 3] == 'b') {
for (int i = c - 5; (text[i] == 'b' || text[i] == 'a') && i > 0; i -= 1) {
if (text[i] == 'b' && text[i - 1] == 'a') {
StVrk += 2;
}
}
}
} else if (text[c - 2] == 'b' && text[c - 3] == 'a') {
StVrk += 2;
if (text[c - 4] == 'b' && text[c - 5] == 'a') {
for (int i = c - 4; (text[i] == 'b' || text[i] == 'a') && i > 0; i -= 1) {
if (text[i] == 'b' && text[i - 1] == 'a')
StVrk += 2;
}
}
}
return 0;
}
}