public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = "";
while(true) {
System.out.println("請輸入壹個字符:");
str = sc.nextLine();
if(str=="exit") // 如果字符串為"exit",退出循環
break;
if(str.length()==1) {
char c = str.charAt(0);
System.out.println("它對應的ASCII碼為:" + (int)c); //(int)c將c強制轉換為它的ascii碼
}
else
System.out.println("請輸入壹位字符。");
}
sc.close();
}
}