Проверьте, является ли символ цифрой на разных языках программирования

В большинстве языков программирования вы можете использовать функцию/метод isdigit(), чтобы проверить, является ли символ цифрой. Вот несколько примеров на популярных языках программирования:

  1. Python:

    char = '5'
    if char.isdigit():
       print("Character is a digit")
    else:
       print("Character is not a digit")
  2. Java:

    char ch = '5';
    if (Character.isDigit(ch)) {
       System.out.println("Character is a digit");
    } else {
       System.out.println("Character is not a digit");
    }
  3. C++:

    char ch = '5';
    if (isdigit(ch)) {
       cout << "Character is a digit" << endl;
    } else {
       cout << "Character is not a digit" << endl;
    }
  4. JavaScript:

    var char = '5';
    if (char.match(/^\d$/)) {
       console.log("Character is a digit");
    } else {
       console.log("Character is not a digit");
    }
  5. C#:

    char ch = '5';
    if (char.IsDigit(ch)) {
       Console.WriteLine("Character is a digit");
    } else {
       Console.WriteLine("Character is not a digit");
    }