Computer Applications

Write a program in Java that reads a word and checks whether it begins with a vowel or not.

Java

Java Conditional Stmts

5 Likes

Answer

import java.util.Scanner;

public class KboatWord
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a word: ");
        String w = in.nextLine();
        char ch = w.charAt(0);
        ch = Character.toUpperCase(ch); 
        if (ch == 'A' ||
            ch == 'E' ||
            ch == 'I' ||
            ch == 'O' ||
            ch == 'U')
            System.out.println("Word begins with a vowel");
        else
            System.out.println("Word does not begin with a vowel");
     }
}

Output

Answered By

3 Likes


Related Questions