Advertisement
Garro

Java - Prueba sumativa 1 - Ejercicio 1 (Miercoles)

Jan 4th, 2012
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class cuenta_vocales_par{   
  3. public static void main (String args[]) {
  4.     String frase;
  5.     int V=0;
  6.     int VT=0;
  7.     int F=-1;
  8.     while(V%2==0){
  9.         VT = VT+V;
  10.         frase = leeFrase();
  11.         V = calculaVocales(frase);
  12.         System.out.println("La frase contiene "+V+" vocales.");
  13.         F++;
  14.     }System.out.println("Vocales total encontradas: "+VT+". Cantidad de frases con cant. vocales pares: "+F);
  15. }
  16. public static String leeFrase(){
  17.     Scanner tec = new Scanner(System.in);
  18.     boolean Func = true;
  19.     String frase = "";
  20.     while (Func){
  21.         System.out.print("Ingrese una frase: ");
  22.         frase = tec.nextLine();
  23.         Func=validaFrase(frase);
  24.     }return frase;
  25. }
  26. public static boolean validaFrase(String f){
  27.     for(int i = 0;i<f.length();i++){
  28.         if(f.charAt(i)!=' '){
  29.             return false;
  30.         }
  31.     }System.out.println("Error. Frase no valida.");  
  32.     return true;
  33. }  
  34. public static int calculaVocales(String f){
  35.     int cont = 0;
  36.     for(int i = 0;i<f.length();i++){
  37.         if(f.charAt(i)=='a'||f.charAt(i)=='e'||f.charAt(i)=='i'||f.charAt(i)=='o'||f.charAt(i)=='u'){
  38.             cont++;
  39.         }
  40.     }return cont;
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement