判断字符
1.数字字符:b>=48&&b<=57
2.大写字母:b>=65&&b<=90
3.小写字母:b>=97&&b<=122
4.算术运算符:b==43||b==45||b==42||b==47||b==37
5.关系运算符:b>=60&&b<=62
6.逻辑运算符:b==38||b==124||33
7.其他字符:
代码展示:
import java.util.Scanner;
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a=sc.next();
char b=a.charAt(0);
if(b>=48&&b<=57){
System.out.println("Number");
}
else if(b>=65&&b<=90){
System.out.println("Capital letter");
}
else if(b>=97&&b<=122){
System.out.println("Lowercase letter");
}
else if(b==43||b==45||b==42||b==47||b==37){
System.out.println("Arithmetic operators");
}
else if(b>=60&&b<=62){
System.out.println("Relational operators");
}
else if(b==38||b==124||b==33){
System.out.println("Logical operators");
}
else{
System.out.println("Other character");
}
}
}
String s=" ",char s=' '