java输入一个字符,如果是字母,则输出相应的ASCII值,如果是数字字符,则转

2024-11-26 03:57:06
推荐回答(1个)
回答1:

public class CharTest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char ch =scanner.next().charAt(0);
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ){
System.out.println((int)ch);
}else if (ch >= '0' && ch <= '9'){
System.out.println(ch);
}

}
}