I'm stuck, they ask me for a program:
This stores a phrase, this phrase is saved in a string array. And then you should take each word separately and count each vowel and consonant, if the word has more vowels the program will print that word and give notice.
Example of output:
Entramos Maria nos mira.
The program will return, your first word Maria has more vowels than consonants.
I have done the first part but I am not able to put together the array part with counting the vowels of a String with the charAt method
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author cbermejo
*/
public class Prueba3 {
private String palabra1="";
private String palabra2="";
private String palabra3="";
private String palabra4="";
private String []texto = null;
Scanner scan = new Scanner (System.in);
public static void main (String []args){
Prueba3 programa = new Prueba3 ();
programa.inici();
}
private void inici(){
mida();
arrayIntro();
Imprimir();
}
private void mida() {
System.out.println("Dime la medida:");
int mida = scan.nextInt();
texto = new String[mida];
}
private void arrayIntro(){
for ( int i=0; i<texto.length; i++){
texto [i]= scan.next();
}
}
private void Imprimir(){
int contador=0;
int contador2 =0;
for ( int i=0; i<texto.length;i++){
//if(texto[i]==texto[0]){
if ((texto[i].charAt(i)=='a')|| (texto[i].charAt(i)=='e')||(texto[i].charAt(i)=='i')||(texto[i].charAt(i)=='o')||(texto[i].charAt(i)=='u')){
contador++;
}else{
contador2++;
}
}
System.out.println(contador);
System.out.println(contador2);
}
}