Here's an example Java program to check whether a given character is a vowel or a consonant:
import java.util.Scanner; public class VowelOrConsonant { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a character: "); char ch = scanner.next().charAt(0); if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') { System.out.println(ch + " is a vowel"); } else { System.out.println(ch + " is a consonant"); } } }
In this program, we use a Scanner
object to read a character from the user. We then check whether the character is one of the vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'). If it is, we print a message saying that the character is a vowel. Otherwise, we print a message saying that the character is a consonant. Note that we use the charAt()
method to extract the first character from the user input.
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.