每日一题
题目
题目描述:
从键盘输入一个字符,判断该字符是否大写字母、小写字母、数字字符或其他字符。分别输出对应的提示信息。
输入输出格式
输入
输入一个字符。
输出
如果该字符是大写字母,则输出“ upper ”;若是小写字母,则输出“ lower ”;若是数字字符,则输出“ digit ”;若是其他字符,则输出“ other ”。(输出不含双引号)。
输入输出样例
样例输入
E
样例输出
upper
Java写法:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
char ch = input.next().charAt(0);
if (ch >= 'A' && ch <= 'Z') {
System.out.println("upper");
} else if (ch >= 'a' && ch <= 'z') {
System.out.println("lower");
} else if (ch >= '0' && ch <= '9') {
System.out.println("digit");
} else {
System.out.println("other");
}
input.close();
}
}
Tips:
C写法:
#include <stdio.h>
int main() {
char ch;
scanf("%c", &ch);
if (ch >= 'A' && ch <= 'Z') {
printf("upper");
} else if (ch >= 'a' && ch <= 'z') {
printf("lower");
} else if (ch >= '0' && ch <= '9') {
printf("digit");
} else {
printf("other");
}
return 0;
}
Tips:
C++写法:
#include <iostream>
using namespace std;
int main() {
char ch;
cin >> ch;
if (ch >= 'A' && ch <= 'Z') {
cout << "upper";
} else if (ch >= 'a' && ch <= 'z') {
cout << "lower";
} else if (ch >= '0' && ch <= '9') {
cout << "digit";
} else {
cout << "other";
}
return 0;
}
Tips:
Python写法:
ch = input()
if ch.isupper():
print("upper")
elif ch.islower():
print("lower")
elif ch.isdigit():
print("digit")
else:
print("other")
Tips:
PHP写法:
<?php
$ch = readline();
if (ctype_upper($ch)) {
echo "upper";
} else if (ctype_lower($ch)) {
echo "lower";
} else if (ctype_digit($ch)) {
echo "digit";
} else {
echo "other";
}
?>
Tips: