问题 问答题

下列程序中,要求从键盘接受字符输入,直到输入字符为“e”(注意是小写)时停止,并且将输入的字符(“e”之前的字符)显示在屏幕上。请将程序补充完整。
程序运行结果如下:
Keep typing,it will stop while enter ’e’...
ddfsofkjlvncozieowdsfadsf
ddfsofkjlvncozi
import java.io.*;
public class ex4_1
public static void main(String[] args)
char ch;
System.out.println("Keep typing,it will stop while enter ’e’...");
try
while((ch= _______)!=’e’)
System._______;

catch(IOException Joe)
System._______;


答案

参考答案:(char)System.in.read()
out.print(ch)
out.println(ioe.getMessage())

解析:
本题主要考查Java基本的I/O输入输出流,while循环语句以及对char类型数据的操作。解题关键是,熟练掌握Java基本的I/O操作,会输出异常信息的基本语句。本题中,第1个空,判断从屏幕中输入的字符是否为“e”,需将读到的字符转换char类型数据,再进行比较;第2个空,填入基本的输出语句,完成将ch中的数据显示到屏幕中;第3个空,会调用返回I/O异常信息的方法,并显示到屏幕中。

多项选择题
单项选择题