问答题

下面是关于字符界面基本输入输出的程序,请在程序的每条横线处填写一个语句,使程序的功能完整。 注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。 ______________________ public class SimpleCharInOut{ public static void main(String args[]){ char c=" "; System.out.println("Enter a character please: "); try{ ____________________//接受用户键盘输入的字符并保存在变量c中 } catch(________________________e){} System.out.println("You’ve entered character "+c); } }

【参考答案】

import java.io.*; c=(char)System.in.read(); IOException或Exce......

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

问答题
下面是一个Applet程序,其功能是实现对JButton类的扩展,封装成上网助力一样的按钮类,每个按钮对象对应一个 URL地址,点击则访问相应的URL。要求在窗口中从上到下排列3个这样的按钮。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。程序运行结果如下:import java.net.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class ex28_3 extends JApplet implements ActionListener {ButtonURL[] btnURL = new ButtonURL[3];public void init() {btnURL[0] = new ButtonURL( 新浪网 , http: www.sina.com.cn );btnURL[1] = new ButtonURL( 163 , http: www.163.com );btnURL[2] = new ButtonURL( 搜狐 , http: www.sohu.com );GridLayout gl = new GridLayout(1,3);getContentPane().setLayout(gl);for (int i = 0; i < btnURL.length; i++) {btnURL[i].addActionListener(this);getContentPane().add(btnURL[i]);}}public void actionPerformed(ActionEvent ae) {ButtonURL btnClick =ae.getSource(); 获取发生事件的对象try {URL load = new URL(btnClick.strAddr);getAppletContext().showDocument(strAddr);} catch (MalformedURLException e) {showStatus( Bad URL: + btnClick.strAddr);}}}class ButtonURL extends JButton {String strAddr;ButtonURL(String strLabel, String strAddress) {super(strLabel);strAddr = strAddress;}} ex28_3.html<HTML><HEAD><TITLE>ex28_3< TITLE>< HEAD><BODY><applet code= ex28_3.class width=800 height=400 >< applet>< BODY>< HTML>