이 기사에서는 문자가 알파벳인지 여부를 확인하는 방법을 이해합니다. 이것은 주어진 문자가 알파벳 a ~ z 또는 A ~ Z 사이에 있는지 확인하여 수행됩니다.
아래는 동일한 데모입니다 -
입력
입력이 -
라고 가정합니다.Enter a character: H
출력
원하는 출력은 -
The character H is an alphabet
알고리즘
Step 1 - START Step 2 - Declare a character value namely my_input Step 3 - Read the required values from the user/ define the values Step 4 - Using an if-else condition, check if the input value lies in between ‘a’ and ‘z’ or ‘A’ and ‘Z’ using comparison operators ‘>=’ and ‘<=’ . If true, its an alphabet, else its not an alphabet/ Step 5 - Display the result Step 6 - Stop
예시 1
여기에서 입력은 프롬프트에 따라 사용자가 입력하고 있습니다. 코딩 기반 도구에서 이 예제를 라이브로 사용해 볼 수 있습니다.
.
import java.util.Scanner;
public class Alphabet {
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 <= 'z') || (my_input >= 'A' && my_input <= 'Z'))
System.out.println("The character " +my_input + " is an alphabet");
else
System.out.println("The character " +my_input + " is not an alphabet");
}
} 출력
Required packages have been imported A reader object has been defined Enter the character : H The character H is an alphabet
예시 2
여기서 정수는 이전에 정의되었으며 그 값은 콘솔에 액세스되어 표시됩니다.
public class Alphabet {
public static void main(String[] args) {
char my_input;
my_input = 'H';
System.out.println("The Alphabet is defined as " +my_input);
if( (my_input >= 'a' && my_input <= 'z') || (my_input >= 'A' && my_input <= 'Z'))
System.out.println("The character " +my_input + " is an alphabet.");
else
System.out.println("The character " +my_input + " is not an alphabet.");
}
} 출력
The Alphabet is defined as H The character H is an alphabet.