1、二级 JAVA 机试-183 及答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:33.00)1.下面的程序是打印输出 100300 之间的不能被 3 整除的数。请在每条横线处填写一条语句,使程序的功能完整。注意:请勿改动 main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。public class printNo3and5void print()int n ;for(n=100 ;n=300 ;n+)if(n%3=0)_System.out.println(n);public static_main(String args)printNo3
2、and5 obj=new printN03and5();_(分数:33.00)_二、2简单应用题(总题数:1,分数:33.00)2.1setText(“请正确输入!“);(分数:33.00)_三、3综合应用题(总题数:1,分数:34.00)3.下面是一个 Applet 程序,其功能是建立一个图形用户界面的窗口,包括一个文本显示区和一个按钮,点击按钮,可以声文本区已有的文本基础上追加显示 10 条“Welcome to China!”信息,并且文本区由滚动条控制文本的上下滚动。请改正程序中的错误(有下画线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。import ja
3、vax.swing.*;import java.awt.*;import java.awt.event.*;/*applet code=“exl3_4.class“width=800 height=400/applet*/public class exl4_3 extends JAppletJButton jb=new JButton(“Add Text“);JTextPane jtp=new JTextPane();public void init()jb.addActionListener(new Ac60nListener()pubhc void actionPerformed(Acti
4、onEvent e)for(int i=1;i10;i+)jtp.geText(jtp.setText()+“Welcome to China! /n“););Container cp=getContentPane();cp.add(new JScrollPane(jtp);cp.add(BorderLayout.SOUTH,jtp);public static void main(Stdng args)ex14_3 obj14_3=new ex14_3();String str=obj14_3.getClass().toString();if(str.indexOf(“class“)!=-1
5、)str=str.substring(6);JFrame frm=new JFrame(str);frm.addWindowListener(new WindowAdapter()pubhc void windowClosing(WindowEvent we)System.exit(0););frm.getContentPane().add(ex3_10);frm.setSize(300,400);frm.setVisible(true);ex14_3.htmlHTMIHEADTITLEex14_3/HEADBODYapplet code=“ex14_3.class“width=800 hei
6、ght=400/applet/BODY/HTML(分数:34.00)_二级 JAVA 机试-183 答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:33.00)1.下面的程序是打印输出 100300 之间的不能被 3 整除的数。请在每条横线处填写一条语句,使程序的功能完整。注意:请勿改动 main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。public class printNo3and5void print()int n ;for(n=100 ;n=300 ;n+)if(n%3=0)_System.out.println(n);publi
7、c static_main(String args)printNo3and5 obj=new printN03and5();_(分数:33.00)_正确答案:(continue;voidobj.print();)解析:二、2简单应用题(总题数:1,分数:33.00)2.1setText(“请正确输入!“);(分数:33.00)_正确答案:(r=a%ba=b)解析:三、3综合应用题(总题数:1,分数:34.00)3.下面是一个 Applet 程序,其功能是建立一个图形用户界面的窗口,包括一个文本显示区和一个按钮,点击按钮,可以声文本区已有的文本基础上追加显示 10 条“Welcome to Ch
8、ina!”信息,并且文本区由滚动条控制文本的上下滚动。请改正程序中的错误(有下画线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。import javax.swing.*;import java.awt.*;import java.awt.event.*;/*applet code=“exl3_4.class“width=800 height=400/applet*/public class exl4_3 extends JAppletJButton jb=new JButton(“Add Text“);JTextPane jtp=new JTextPane();pu
9、blic void init()jb.addActionListener(new Ac60nListener()pubhc void actionPerformed(ActionEvent e)for(int i=1;i10;i+)jtp.geText(jtp.setText()+“Welcome to China! /n“););Container cp=getContentPane();cp.add(new JScrollPane(jtp);cp.add(BorderLayout.SOUTH,jtp);public static void main(Stdng args)ex14_3 ob
10、j14_3=new ex14_3();String str=obj14_3.getClass().toString();if(str.indexOf(“class“)!=-1)str=str.substring(6);JFrame frm=new JFrame(str);frm.addWindowListener(new WindowAdapter()pubhc void windowClosing(WindowEvent we)System.exit(0););frm.getContentPane().add(ex3_10);frm.setSize(300,400);frm.setVisible(true);ex14_3.htmlHTMIHEADTITLEex14_3/HEADBODYapplet code=“ex14_3.class“width=800 height=400/applet/BODY/HTML(分数:34.00)_正确答案:(setText(jtp.getText() +“Welcome to China! /n“)cp.add(BorderLayout.SOUTH,jb)frm.getContentPane().add(obj14_3)解析: