问答题 本题中,主窗口有一个按钮“打开对话框”和一个文本域,单击按钮“打开对话框”后会弹出一个对话框,对话框上有两个按钮“Yes"和“N0”,单击对话框上的“Yes”和“N0”按 钮后返回主窗口,并在右侧文本域中显示刚才所单击的按钮信息。 import java.awt.event.*; import java.awt.*; class MyDialog implements ActionListener {static final int YES=1,N0=0; int message=-1;Button yes,no; MyDialog(Frame f.String S,boolean b) {super(f,S,b); ves=new Button("Yes");yes.addActionListener (this); no=new Button("No"); no.addActionListener (this)o setLayout(new FlowLayout()); add(yes);add(no); setBounds(60,60,100,100); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {message=-1;setVisible(false);) }); } public void actionPerformed(ActionEvent e) {if(e.getSource()= =yes) {message=YES; setVisible(false); } else if(e.getSource()= = no) {message=NO; setVisible(false); } } public int getMessage() {return message; } } class Dwindow extends Frame implements ActionLis- tener {TextArea text;Button button;MyDialog dialog; Dwindow(String s) {super(s); text=new TextArea(5,22);button=new Button ("打开对话框"); button.addActionListener(this); setLayout(new FlowLayout()); add(button);add(text); dialog=new MyDialog(this,"Dialog",true); setBounds(60,60,300,300);setVisible(true); validate(); addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);} }); } public void actionPerformed(ActionEvent e) {if(e.getSource()= =button) {; if(dialog.getMessage()= =MyDialog.YES) {text.append("\n你单击了对话框的yes按 钮"); } else if(dialog.getMessage()= =MyDialog.NO) {text.append("\n你单击了对话框的N0按 钮"); } } } } public class java2 {public static void main(String args[]) {new Dwindow("java2"); } }
问答题 本题中数组arr中存储了学生的成绩,分别为87,45,56,78,67,56,91,62,82,63,程序的功能是计算低于平均分的人数,并打印输出结果。请在程序空缺部分填写适当内容。使程序能正确运行。 public class javal{ public static void main(String[]args){ int arr[]={56,91,78,67,56,87,45,62,82,63}; int num=arr.length int i=0; int sumScore= 0; int sumNum=0; double average; while(i<num){ sumScore=sumScore+arr[i]; ; } average= ; i=0; do{ if(arr[i]<average) sumNum++: i++; }while( ); System.OUt.println("average:"+average+",be- lows average:"+sumNum); } }
判断题 规模较大的高校可实行“统一领导、分级管理”的财务管理体制。( )