问题
单项选择题
下面程序中,若从键盘输入大写字母C,则程序的输出结果是______。import java.io.*;public class Test{ public static void main(String args[ ]){ int ch=0; System.out.println("Please input a character:"); try{ch=System.in.read( );char ch_A=’A’,ch_Z=’Z’;int delta_c=(int)ch_A+(int)ch_Z-ch;System.Out.println("the encoded character is:"+(char)delta_C); }catch(IOException e){e.printStackTrace( );} }}
A.C
B.Y
C.X
D.字母C的ASCII码的整型值
答案
参考答案:C
解析: 使用ch=System.in.read( )语句从键盘读入大写字母C并赋给ch,此时ch值为67,也就是字母C的ASCII码值。语句(int)ch_A+(int)ch_Z-ch的结果为88,ASCII码的88相当于字母X,所以输出为X,选项C正确。