/* * 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"); } }
Modifié par Whismeril le 28/01/2015 à 14:14
EDIT: Ajout de la coloration syntaxique.