ICSE Class 10 Computer Applications Question 19 of 43

Conditional Constructs in Java — Question 19

Back to all questions
19
Question

Question 19

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

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
BlueJ output of KboatWord.java