lundi 4 novembre 2019

how to check how many vocals a string contains [duplicate]

This question already has an answer here:

my idea:

import java.util.Scanner;

public class Vokale {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);
String Zeichenkette = "";
int anzVokale = 0; int anzKonsonanten = 0; int restlZeichen = 0;
char [] Vokal = {'a','e','i','o','u'};

System.out.println("Gebe eine Zeichenkette ein!");

Zeichenkette = input.nextLine();
Zeichenkette.toLowerCase();

for (int i = 0; i < Zeichenkette.length(); i++) {

        if (Vokal.equals(Zeichenkette.charAt(i)) ) {
            anzVokale++;

        }



}

System.out.println(anzVokale);

}

}

I created an array with the vocals inside. I initiated a variable "Zeichenkette" which has to be entered by the user. The loop should check if every single letter is part of the vocal array and if its true the program should increase the variable "anzVokale" by 1 , but the output is still 0.

Aucun commentaire:

Enregistrer un commentaire