【计算机类职业资格】二级JAVA机试-201及答案解析.doc

上传人:inwarn120 文档编号:1326518 上传时间:2019-10-17 格式:DOC 页数:8 大小:40KB
下载 相关 举报
【计算机类职业资格】二级JAVA机试-201及答案解析.doc_第1页
第1页 / 共8页
【计算机类职业资格】二级JAVA机试-201及答案解析.doc_第2页
第2页 / 共8页
【计算机类职业资格】二级JAVA机试-201及答案解析.doc_第3页
第3页 / 共8页
【计算机类职业资格】二级JAVA机试-201及答案解析.doc_第4页
第4页 / 共8页
【计算机类职业资格】二级JAVA机试-201及答案解析.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

1、二级 JAVA 机试-201 及答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.本题程序将字符串 sir 中的字符 a 用符号代替,然后将字符串中第一个字符前的听有字符去掉,并打印输出最后的 str 字符串。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。public class basicpublic static void main(String args)String str = “Iamagoodboy,andwhataboutyou?“;str =_;int pos =_;str =_;System.out.p

2、rintln (str);(分数:30.00)_二、2简单应用题(总题数:1,分数:40.00)2.本题程序的功能是主窗口有一个按钮、一个文本域和一个复选框,初始时窗口的大小是不能调整的,勾选复选框后,窗口大小就可以进行调整,如果取消勾选复选框,则窗口的大小又不能调整,单击按钮可以关闭程序。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。import java.awt.*;import java.awt.event.*;class MyFrame extends Frame_Checkbox box;TextArea text;Button button;MyFrame(St

3、ring s)super (s);box = new Checkbox(“设置窗口是否可调整大小“);text = new TextArea(12,12);button = new Button(“关闭窗口“);button.addActionListener(this);box.addItemListener(this);setBounds(100,100,200,300);setVisible(true);add(text,BorderLayout.CENTER);add(box,BorderLayout.SOUTH);add(button,BorderLayout.NORTH);_;va

4、lidate ();public void itemStateChanged(ItemEvent e)if (box.getState() = true)setResizable(true);elsesetResizable(false);public void actionPerformed(ActionEvent e)dispose();class simplepublic static void main(String args)new MyFrame(“simple“);(分数:40.00)_三、3综合应用题(总题数:1,分数:30.00)3.本题程序是一个 Applet 应用程序,功

5、能是计算前 n 个自然数的和,程序中用进度条来表示计算的进程。页面中有两个文本框、两个按钮和一个进度条,在第一个文本框中输入要计算的自然数的个数,单击“开始”按钮则开始进行计算,进度条同步显示计算完成的情况。程序中存在若干错误,请找出并改正(注意:不得改动程序的结构,不得增行或删行)。import javax.swing.*;import javax.swing.border.*;import java.awt.*;import java.awt.event.*;public class advance extends JappletContainer container = null;JBu

6、tton startButton,stopButton;JTextField inputTextField,outputTextField;JProgressBar pBar = null;Timer timer = null;static int sum = 0;static int counter = 0;public void init()container = this.getContentPane();container.setLayout(new GridLayout(3,1);Box hboxl = Box.createHorizontalBox();container.add(

7、hboxl);hboxl.add(Box.createHorizontalGlue();JLabel labell = new JLabel(“前“,JLabeI.LEFT);labell.setFont(new Font(“Dialog“,Font.PLAIN,15);hboxl.add(labell);inputTextField = new JTextField(“100“,4);hboxl.add(inputTextField);JLabel label2 = new JLabel(“个自然数和是“,JLabel.LEFT);label2.setFont(new Font(“Dialo

8、g“,Font.PLAIN,15);hboxl.add(label2);outputTextField = new JTextField(10);hboxl.add(outputTextField);hboxl.add(Box.createHorizontalGlue();Box hbox2 = Box.createHorizontalBox();container.add(hbox2);startButton : new JButton(“开始“);startButton.addActionListener(new ButtonListener();hbox2.add(Box.createH

9、orizontalGlue();hbox2.add(startButton);hbox2.add(Box.createHorizontalGlue();stopButton = new JButton(“结束“);stopButton.addActionListener(new ButtonListener() ;hbox2.add(Box.createHorizontalGlue();hbox2.add(stopButton);hbox2.add(Box.createHorizontalGlue();pBar = new JProgressBar();pBar.setStringPainte

10、d(true);Border border = BorderFactory.createLineBorder(Color.red,2);pBar.setBorder(border);pBar.setBackground(Color.white);pBar.setForeground(Color.blue);pBar.setMinimum(0);pBar.setMaximum(Integer.parseInt(inputTextField.getText();container.add(pBar);timer = new Timer(0,TimerListener();class TimerLi

11、stener implements ActionListenerpublic void actionPerformed(ActionEvent e)if (Integer.parseInt (inputTextField.getText () 0)counter +;sum = sum+counter;pBar.setValue (counter);outputTextField,setText (Integer.toString (sum);elseoutputTextField,setText (“0“);if (counter = Integer.parseInt(inputTextFi

12、eld.getText ()timer,stop ();class ButtonListener implements ActionListenerpublic void actionPerformed(ActionEvent e)JButton button = e.getSource();if (button.getText () = “开始“)outputTextField,setText (“);if (inputTextField.getText() != “ “)pBar.setMaximum (Integer.parseInt (inputTextField.getText ()

13、 );sum = 0 ;counter = 0;timer.begin ();elseif (button.getText () =“结束“)timer,stop ();outputTextField,setText (“);sum = 0;counter = 0;pBar.setValue(0);(分数:30.00)_二级 JAVA 机试-201 答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.本题程序将字符串 sir 中的字符 a 用符号代替,然后将字符串中第一个字符前的听有字符去掉,并打印输出最后的 str 字符串。请将下述程序补充

14、完整(注意:不得改动程序的结构,不得增行或删行)。public class basicpublic static void main(String args)String str = “Iamagoodboy,andwhataboutyou?“;str =_;int pos =_;str =_;System.out.println (str);(分数:30.00)_正确答案:(str.replace(a,)。str.indexOf(“)。str.substring(pos)。)解析:二、2简单应用题(总题数:1,分数:40.00)2.本题程序的功能是主窗口有一个按钮、一个文本域和一个复选框,初

15、始时窗口的大小是不能调整的,勾选复选框后,窗口大小就可以进行调整,如果取消勾选复选框,则窗口的大小又不能调整,单击按钮可以关闭程序。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。import java.awt.*;import java.awt.event.*;class MyFrame extends Frame_Checkbox box;TextArea text;Button button;MyFrame(String s)super (s);box = new Checkbox(“设置窗口是否可调整大小“);text = new TextArea(12,12);bu

16、tton = new Button(“关闭窗口“);button.addActionListener(this);box.addItemListener(this);setBounds(100,100,200,300);setVisible(true);add(text,BorderLayout.CENTER);add(box,BorderLayout.SOUTH);add(button,BorderLayout.NORTH);_;validate ();public void itemStateChanged(ItemEvent e)if (box.getState() = true)set

17、Resizable(true);elsesetResizable(false);public void actionPerformed(ActionEvent e)dispose();class simplepublic static void main(String args)new MyFrame(“simple“);(分数:40.00)_正确答案:(implements ItemListener,ActionListener。setResizable(false)。)解析:三、3综合应用题(总题数:1,分数:30.00)3.本题程序是一个 Applet 应用程序,功能是计算前 n 个自然

18、数的和,程序中用进度条来表示计算的进程。页面中有两个文本框、两个按钮和一个进度条,在第一个文本框中输入要计算的自然数的个数,单击“开始”按钮则开始进行计算,进度条同步显示计算完成的情况。程序中存在若干错误,请找出并改正(注意:不得改动程序的结构,不得增行或删行)。import javax.swing.*;import javax.swing.border.*;import java.awt.*;import java.awt.event.*;public class advance extends JappletContainer container = null;JButton startB

19、utton,stopButton;JTextField inputTextField,outputTextField;JProgressBar pBar = null;Timer timer = null;static int sum = 0;static int counter = 0;public void init()container = this.getContentPane();container.setLayout(new GridLayout(3,1);Box hboxl = Box.createHorizontalBox();container.add(hboxl);hbox

20、l.add(Box.createHorizontalGlue();JLabel labell = new JLabel(“前“,JLabeI.LEFT);labell.setFont(new Font(“Dialog“,Font.PLAIN,15);hboxl.add(labell);inputTextField = new JTextField(“100“,4);hboxl.add(inputTextField);JLabel label2 = new JLabel(“个自然数和是“,JLabel.LEFT);label2.setFont(new Font(“Dialog“,Font.PLA

21、IN,15);hboxl.add(label2);outputTextField = new JTextField(10);hboxl.add(outputTextField);hboxl.add(Box.createHorizontalGlue();Box hbox2 = Box.createHorizontalBox();container.add(hbox2);startButton : new JButton(“开始“);startButton.addActionListener(new ButtonListener();hbox2.add(Box.createHorizontalGl

22、ue();hbox2.add(startButton);hbox2.add(Box.createHorizontalGlue();stopButton = new JButton(“结束“);stopButton.addActionListener(new ButtonListener() ;hbox2.add(Box.createHorizontalGlue();hbox2.add(stopButton);hbox2.add(Box.createHorizontalGlue();pBar = new JProgressBar();pBar.setStringPainted(true);Bor

23、der border = BorderFactory.createLineBorder(Color.red,2);pBar.setBorder(border);pBar.setBackground(Color.white);pBar.setForeground(Color.blue);pBar.setMinimum(0);pBar.setMaximum(Integer.parseInt(inputTextField.getText();container.add(pBar);timer = new Timer(0,TimerListener();class TimerListener impl

24、ements ActionListenerpublic void actionPerformed(ActionEvent e)if (Integer.parseInt (inputTextField.getText () 0)counter +;sum = sum+counter;pBar.setValue (counter);outputTextField,setText (Integer.toString (sum);elseoutputTextField,setText (“0“);if (counter = Integer.parseInt(inputTextField.getText

25、 ()timer,stop ();class ButtonListener implements ActionListenerpublic void actionPerformed(ActionEvent e)JButton button = e.getSource();if (button.getText () = “开始“)outputTextField,setText (“);if (inputTextField.getText() != “ “)pBar.setMaximum (Integer.parseInt (inputTextField.getText () );sum = 0

26、counter = 0;timer.begin ();elseif (button.getText () =“结束“)timer,stop ();outputTextField,setText (“);sum = 0;counter = 0;pBar.setValue(0);(分数:30.00)_正确答案:(第 53 行的“timer=new Timer(0,TimerListener()“改为“timer=new Timer(0,new TimerListener()“。第 79 行的“JBuRon buRon=e.getSource()“改为“JButton button=(JButton)e.getSource()“。第 88 行的“timer.begin()“改为“timer.start()“。)解析:

展开阅读全文
相关资源
猜你喜欢
  • ETSI ETS 300 509-1994 European Digital Cellular Telecommunications System (Phase 2) Subscriber Identity Modules (SIM) Functional Characteristics (GSM 02 17 Version 4 3 3)《欧洲数字蜂窝通信系_1.pdf ETSI ETS 300 509-1994 European Digital Cellular Telecommunications System (Phase 2) Subscriber Identity Modules (SIM) Functional Characteristics (GSM 02 17 Version 4 3 3)《欧洲数字蜂窝通信系_1.pdf
  • ETSI ETS 300 510-1996 Digital Cellular Telecommunications System (Phase 2) Description of Charge Advice Information (CAI) (GSM 02 24 Second Edition Version 4 5 0)《数字蜂窝通信系统(第2阶段) 收费.pdf ETSI ETS 300 510-1996 Digital Cellular Telecommunications System (Phase 2) Description of Charge Advice Information (CAI) (GSM 02 24 Second Edition Version 4 5 0)《数字蜂窝通信系统(第2阶段) 收费.pdf
  • ETSI ETS 300 510-1996 Digital Cellular Telecommunications System (Phase 2) Description of Charge Advice Information (CAI) (GSM 02 24 Second Edition Version 4 5 0)《数字蜂窝通信系统(第2阶段) 收费_1.pdf ETSI ETS 300 510-1996 Digital Cellular Telecommunications System (Phase 2) Description of Charge Advice Information (CAI) (GSM 02 24 Second Edition Version 4 5 0)《数字蜂窝通信系统(第2阶段) 收费_1.pdf
  • ETSI ETS 300 511-1995 European Digital Cellular Telecommunications System (Phase 2) Man-Machine Interface (MMI) of the Mobile Station (MS) (GSM 02 30 Second Edition Version 4 13 0).pdf ETSI ETS 300 511-1995 European Digital Cellular Telecommunications System (Phase 2) Man-Machine Interface (MMI) of the Mobile Station (MS) (GSM 02 30 Second Edition Version 4 13 0).pdf
  • ETSI ETS 300 511-1995 European Digital Cellular Telecommunications System (Phase 2) Man-Machine Interface (MMI) of the Mobile Station (MS) (GSM 02 30 Second Edition Version 4 13 0)_1.pdf ETSI ETS 300 511-1995 European Digital Cellular Telecommunications System (Phase 2) Man-Machine Interface (MMI) of the Mobile Station (MS) (GSM 02 30 Second Edition Version 4 13 0)_1.pdf
  • ETSI ETS 300 512-1996 Digital Cellular Telecommunications System (Phase 2) Procedure for Call Progress Indications (GSM 02 40 Second Edition Version 4 5 0)《数字蜂窝通信系统(第2阶段) 呼叫进行指示程序 .pdf ETSI ETS 300 512-1996 Digital Cellular Telecommunications System (Phase 2) Procedure for Call Progress Indications (GSM 02 40 Second Edition Version 4 5 0)《数字蜂窝通信系统(第2阶段) 呼叫进行指示程序 .pdf
  • ETSI ETS 300 512-1996 Digital Cellular Telecommunications System (Phase 2) Procedure for Call Progress Indications (GSM 02 40 Second Edition Version 4 5 0)《数字蜂窝通信系统(第2阶段) 呼叫进行指示程序 _1.pdf ETSI ETS 300 512-1996 Digital Cellular Telecommunications System (Phase 2) Procedure for Call Progress Indications (GSM 02 40 Second Edition Version 4 5 0)《数字蜂窝通信系统(第2阶段) 呼叫进行指示程序 _1.pdf
  • ETSI ETS 300 513-1994 European Digital Cellular Telecommunications System (Phase 2) Operator Determined Barring (GSM 02 41 Version 4 5 2)《欧洲数字蜂窝通信系统(第2阶段) 运营商决定的闭锁业务 GSM 02 41(第4 5.pdf ETSI ETS 300 513-1994 European Digital Cellular Telecommunications System (Phase 2) Operator Determined Barring (GSM 02 41 Version 4 5 2)《欧洲数字蜂窝通信系统(第2阶段) 运营商决定的闭锁业务 GSM 02 41(第4 5.pdf
  • ETSI ETS 300 514-1998 Digital Cellular Telecommunications System (Phase 2) Line Identification Supplementary Services - Stage 1 (Third Edition GSM 02 81 Version 4 6 1)《数字蜂窝通信系统(第2阶.pdf ETSI ETS 300 514-1998 Digital Cellular Telecommunications System (Phase 2) Line Identification Supplementary Services - Stage 1 (Third Edition GSM 02 81 Version 4 6 1)《数字蜂窝通信系统(第2阶.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1