Comptage de voyelles , espaces , et de consonnes dans une chaine de caractère

cs_arantess Messages postés 1 Date d'inscription jeudi 12 avril 2012 Statut Membre Dernière intervention 13 novembre 2014 - 13 nov. 2014 à 15:37
cs_arantess Messages postés 1 Date d'inscription jeudi 12 avril 2012 Statut Membre Dernière intervention 13 novembre 2014 - 13 nov. 2014 à 15:37
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/54849-comptage-de-voyelles-espaces-et-de-consonnes-dans-une-chaine-de-caractere

Voici un nouveau programme beaucoup plus *comment dire* évoluer....
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package crypto;

import java.util.Scanner;

/**
 *
 * @author inconnu
 */
public class Exercice {

    public static boolean isVoyelle(char ch) {
        if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i'
                || ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u'
                || ch == 'U' || ch == 'y' || ch == 'Y') {
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int nbVoy = 0;
        String Chaine;
        String phrase;
        char ch;
        System.out.println("Entrer une phrase");
        Chaine = s.nextLine();
        for (int i = 0; i < Chaine.length(); i++) {
            ch = Chaine.charAt(i);
            if (isVoyelle(ch)) {
                nbVoy = nbVoy + 1; //nbVoy++
            }
        }
        System.out.println(nbVoy + "voyelles");
    }
}


EDIT: Ajout de la coloration syntaxique.