tags:

views:

71

answers:

6
public static void ejemplosString(String palabra){
        char[] letras = palabra.toCharArray();
        int contadorVocales = 0;

        for (int i = 0; i < letras.length; i++) {            
            if (char[i] == 'a') {
                contadorVocales++;                
            }

            if (char[i] == "e") {
                contadorVocales++;                
            }

            if (char[i] == "i") {
                contadorVocales++;                
            }

            if (char[i] == "o") {
                contadorVocales++;                
            }

            if (char[i] == "u") {
                contadorVocales++;                
            }
        }
    }

Getting the error on every If statement. Any guidance?

Even when changing the vowels to single quotes, I still get this error:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unexpected type
  required: value
  found:    class
        at practico1.Main.ejemplosString(Main.java:64)
        at practico1.Main.main(Main.java:34)
Java Result: 1
+3  A: 

Change the double-quotes around your letters to single quotes. It looks like the 'a' is correct (it's a character literal), but the other letters ("e", "i", etc.) are all string literals.

Andy White
+6  A: 

Your variable name is letras not char

Naveen
What a glaring mistake. Thanks.
Serg
+3  A: 

Strings use a double quote ", but Characters use a single quote '. Since you are comparing characters, you need to switch to single quotes.

Also, char[i] is not valid java. I think you meant letras[i]

webdestroya
A: 

Shouldn't you be using a .equals() method to compare strings?

Vaishak Suresh
A: 

Are you using any IDE?

A: 

Naveen already gave the right answer

I wanted to add that you could also use the

Java Switch Statement

to implement this Function

KroaX