public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("请输入一个字符:"); char c = scanner.next().charAt(0); System.out.println("您输入的字符是:" + c); System.out.println("该字符的 ASCII 码是:" + (int)c); } }
// C++ 代码示例 #include <iostream> using namespace std;