vendredi 20 novembre 2020

CharacterIterator with switch statement and if statement

i tryed an CharacterIterator and the Switch Statement works fine just if i try to add a If statement within the case for i it shows me nothing. Could you tell me where my mistake is?

StringBuilder sb = new StringBuilder(input);
CharacterIterator it= new StringCharacterIterator(input);{
for(char ch = it.first(); ch!= CharacterIterator.DONE; ch = it.next()) {
    switch(ch) {
    case 'E':
        sb.append("S");
        break;
    case 'n':
        sb.append("O");
        break;
    case 'g':
        sb.append("L");
        break;
    case 'a':
        sb.append(".");
        break;
    case 'i':
        if(it.previous() == ' ') {
            sb.append("ai");
            break;
        }
        break;
    case ' ':
        sb.append(" ");
        break;
    } } }

There is my code. The output of "Engine" should be "SOLai" and i try to check if character "i" is in the beginning of the word or some where else. So that if its in the beginning my output will replace the "i" with an "ai" and if its not it should delete it.

Aucun commentaire:

Enregistrer un commentaire