📜  检查输入字符是字母,数字还是特殊字符

📅  最后修改于: 2021-05-30 02:22:50             🧑  作者: Mango

所有字符,无论是字母,数字还是特殊字符都具有ASCII值。用户输入的字符将确定它是字母,数字还是特殊字符。
ASCII值范围-

  • 对于大写字母65 – 90
  • 对于小字母97 – 122
  • 对于数字48 – 57

例子 :

Input : 8
Output : Digit

Input : E
Output : Alphabet
C++
// CPP program to find type of input character
#include 
using namespace std;
 
void charCheck(char input_char)
{
    // CHECKING FOR ALPHABET
    if ((input_char >= 65 && input_char <= 90)
        || (input_char >= 97 && input_char <= 122))
        cout << " Alphabet ";
 
    // CHECKING FOR DIGITS
    else if (input_char >= 48 && input_char <= 57)
        cout << " Digit ";
 
    // OTHERWISE SPECIAL CHARACTER
    else
        cout << " Special Character ";
}
 
// Driver Code
int main()
{
    char input_char = '$';
    charCheck(input_char);
    return 0;
}


Java
// Java program to find type of input character
import java.io.*;
 
class GFG {
 
    static void charCheck(char input_char)
    {
        // CHECKING FOR ALPHABET
        if ((input_char >= 65 && input_char <= 90)
            || (input_char >= 97 && input_char <= 122))
            System.out.println(" Alphabet ");
 
        // CHECKING FOR DIGITS
        else if (input_char >= 48 && input_char <= 57)
            System.out.println(" Digit ");
 
        // OTHERWISE SPECIAL CHARACTER
        else
            System.out.println(" Special Character ");
    }
 
    // Driver Code
    public static void main(String[] args)
    {
        char input_char = '$';
        charCheck(input_char);
    }
}
 
// This code is contributed by vt_m.


Python3
# python program to find type of
# input character
 
def charCheck(input_char):
     
    # CHECKING FOR ALPHABET
    if ((int(ord(input_char)) >= 65 and
        int(ord(input_char)) <= 90) or
        (int(ord(input_char)) >= 97 and
        int(ord(input_char)) <= 122)):
        print( " Alphabet ")
     
    # CHECKING FOR DIGITS
    elif (int(ord(input_char)) >= 48 and
            int(ord(input_char)) <= 57):
        print(" Digit ")
 
    # OTHERWISE SPECIAL CHARACTER
    else:
        print(" Special Character ")
 
# Driver Code
input_char = '$'
charCheck(input_char)
 
# This code is contributed by Sam007.


C#
// C# program to find type of
// input character
using System;
 
class GFG {
 
    // Function to check type
    // of input character
    static void charCheck(char input_char)
    {
        // Checking for Alphabet
        if ((input_char >= 65 && input_char <= 90)
            || (input_char >= 97 && input_char <= 122))
            Console.WriteLine(" Alphabet ");
 
        // Checking for Digits
        else if (input_char >= 48 && input_char <= 57)
            Console.WriteLine(" Digit ");
 
        // Otherwise Special Character
        else
            Console.WriteLine("Special Character");
    }
 
    // Driver Code
    public static void Main()
    {
        char input_char = '$';
        charCheck(input_char);
    }
}
 
// This code is contributed by vt_m.


PHP
= 65 && $input_char <= 90)
        || ($input_char >= 97 && $input_char <= 122))
        echo " Alphabet ";
     
    // CHECKING FOR DIGITS
    else if ($input_char >= 48 &&
            $input_char <= 57)
    echo " Digit ";
 
    // OTHERWISE SPECIAL CHARACTER
    else                                   
    echo " Special Character ";
}
 
// Driver Code
$input_char = '$';
charCheck($input_char);
 
// This code is contributed by Sam007
?>


Javascript


输出 :

Special Character 
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”