问题 单项选择题

下列程序中,若从键盘中输入的是大写字母C,则程序输出的结果是( )。   Importjava.io.*;   public class Exam{   public static void main(String args[]){   int ch=0;   System.out.println("输入一个字符:");   try{   ch=System.in.read();   charch_A=’A’,ch_Z=’Z’;   int delta c=(int)ch A+(int)ch Z-ch;   syStem. out.println("编码后的字符为:"+(char)delta_c);   }   catch(IOException e){   e.printStackTrace();   }   }   }

A.C

B.Y

C.X

D.字母C的ASCIl码的整型值

答案

参考答案:C

解析:【解析】本题考查考生阅读Java程序的能力。当使用h=System.in.read()语句从键盘读入大写字母C赋给ch,此时ch值为67,也就是字母C的ASCIl值。语句(int) ch_A+(int)ch_Z-ch结果为88,ASCIl码中的88相当于字母X,所以输出为X,选项C正确。

选择题
问答题