mardi 15 septembre 2020

Why is JAVA giving me an error when I use else-if statements [closed]

I'm having trouble with else if. When ever I try to use it JAVA always gives me an error but I'm not sure why. I'll include an example of code. (I'm very much a beginner in this subject)

package ex2;

import java.util.Scanner;

public class Question_2 {

  public static void main(String[] args) {
    /** Name
     * Date
     * Program reads input and count the number of vowels in the word
     */
    Scanner str = new Scanner(System.in);
    System.out.println("Please enter a word: ");
    String word = str.next();
    int count = 0;
    for (int x = 0; x < word.length(); x++)
    {
        if (word.charAt(x) == 'a' || word.charAt(x) == 'e' || 
            word.charAt(x) == 'i' || word.charAt(x) == 'o' || 
            word.charAt(x) == 'u' ||word.charAt (x) == 'y')
        {
            count++;
        }
    }
    if (count >= 1);
    System.out.println("The number of vowels is: " + count);
    
    else if (count == 0); //This is where I'm having trouble
        System.out.println("This word has no vowels in it.");
    str.close();
  }
}

Aucun commentaire:

Enregistrer un commentaire