Java 程序检查字母表是元音还是辅音

javaobject oriented programmingprogramming更新于 2024/4/15 21:32:17

在本文中,我们将了解如何检查字母表是元音还是辅音。包含 'a' 'e' 'i' 'o' 'u' 的字母表称为元音,所有其他字母表称为辅音。

下面是相同的演示 −

输入

假设我们的输入是 −

输入字符:i

输出

所需的输出将是 −

The character : i is a vowel

算法

Step 1 - START
Step 2 - Declare a char value namely my_input.
Step 3 - Read the required values from the user/ define the values
Step 4 - Using an if condition, check if the input is equal to 'a' 'e' 'I' 'o' 'u' values. If yes, its an vowel. Else it's a consonant.
Step 5 - Display the result
Step 6 - Stop

示例 1

import java.util.Scanner;
public class VowelAndConsonant {
   public static void main(String[] args) {
      char my_input;
      System.out.println("Required packages have been imported");
      Scanner my_scanner = new Scanner(System.in);
      System.out.println("A reader object has been defined ");
      System.out.print("Enter the character : ");
      my_input = my_scanner.next().charAt(0);
      if(my_input == 'a' || my_input == 'e' || my_input == 'i' || my_input == 'o' || my_input == 'u' )
         System.out.println("The character : " +my_input + " is a vowel");
      else
         System.out.println("The character : " +my_input + " is a consonant");
   }
}

输出

Required packages have been imported
A reader object has been defined
Enter the character : i
The character : i is a vowel

示例 2

这里,整数已经被预先定义,并且它的值被访问并显示在控制台上。

public class VowelAndConsonant {
   public static void main(String[] args) {
      char my_input = 'i';
      System.out.println("The character is defined as :" +my_input);
      if(my_input == 'a' || my_input == 'e' || my_input == 'i' || my_input == 'o' || my_input == 'u' )
         System.out.println("The character : " +my_input + " is a vowel");
      else
         System.out.println("The character : " +my_input + " is a consonant");
   }
}

输出

The character is defined as :i
The character : i is a vowel

相关文章


有用资源