问答题

基本操作题 下列程序中,要求从键盘接受字符输入,直到输入字符为"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 ioe){ System. ; } } }

【参考答案】

(char)System.in.read()out.print(ch)out.println(ioe.getMessag......

(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)
热门 试题

多项选择题
简单应用题请完成下列Java程序:制作一个图形用户界面,上方包含一个TextField和Button构件,实现输入字符串,点击Button获取文本区的字符;中间显示Label的内容;下方是4个按钮,分别实现控制Label在最左边,在中间,在右边和退出程序的功能。注意:请勿改动main( )主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:import java.awt.*;import java.awt.event.*;public class ex15_2 extends Frame implements ActionListener {private Label l;private TextField tf;public static void main(String[] arg) {ex15_2 obj15_2 = new ex15_2();}public ex15_2() {setBackground(Color.gray);l = new Label( Welcom to the NCR Examination! );Font font = new Font( TimesRoman ,Font.BOLD,20);l.setFont(font);add( Center ,l);Panel p = new Panel();Button b = new Button( Left );b.addActionListener(this);p.add(b);b = new Button( Center );b.addActionListener(this);p.add(b);b = new Button( Right );b.addActionListener(this);p.add(b);b = new Button( Exit );b.addActionListener(this);p.add(b);;p = new Panel();tf = new TextField(40);p.add(tf);b = new Button( Set );b.addActionListener(this);p.add(b);add( North ,p);setSize(500,300);show();}public void actionPerformed(ActionEvent ae) {if(ae.getActionCommand().equals( Exit ))System.exit(0);else if(ae.getActionCommand().equals( Left ));else if(ae.getActionCommand().equals( Center ))l.setAlignment(Label.CENTER);else if(ae.getActionCommand().equals( Right ))l.setAlignment(Label.RIGHT);else if(ae.getActionCommand().equals( Set ))l.setText(tf.getText());}}