程序填空题 1、定义一个长度为 5 的字符串数组,并初始化其初值为“open”, “door”, “the”, “open”, “name”;计算该数组中 “open”出现的次数,并倒序输出数组元素
public class Test{ public void static main(String[] args){ //声明并初始化数组 (1) int count = 0; //计算该数组中 “open”出现的次数 (2) { (3) count++; } //倒序输出数组元素 (4) { (5) } } } 2、定义一个抽象类 AbstractTest,其中有一个公共的抽象方法 printMsg()
然后定义此抽象类的一个子类 DefaultTest,包括的成员变量有姓名,学号,分数,且此类中包括二个构造方法
abstract class AbstractTest{ (1) } (2) { String name; String id; int score; //接收三个参数的构造方法 (3) //接收姓名和学号二个参数的构造方法 (4) //实现抽象方法,方法体为打印出学生的姓名与成绩 (5) } 3、编写程序实现窗口,包含一个标签、一个文本框和一个按钮,当用户单击按钮时,程序把文本框中的内容提制到标签中
(使用 AWT) //引入相关包 (1) public MyFrame{ public MyFrame(){ Frame fr = new Frame(); //设置窗体的布局为FlowLayout (2) Label lbl = new Label(“Init info”); TextField txt = new TextField(30); Button btn = new Button(“Sure”); fr
add(lbl); fr
add(txt);