ImageVerifierCode 换一换
格式:DOC , 页数:8 ,大小:37.50KB ,
资源ID:1326590      下载积分:5000 积分
快捷下载
登录下载
邮箱/手机:
温馨提示:
如需开发票,请勿充值!快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝扫码支付 微信扫码支付   
注意:如需开发票,请勿充值!
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【http://www.mydoc123.com/d-1326590.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(【计算机类职业资格】二级JAVA机试-69及答案解析.doc)为本站会员(周芸)主动上传,麦多课文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知麦多课文库(发送邮件至master@mydoc123.com或直接QQ联系客服),我们立即给予删除!

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

1、二级 JAVA 机试-69 及答案解析(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.本题中定义了一个长度为 20 的整数数组,然后将 120 分别赋给数组元素,计算该数组中所有下标为奇数的元素的和。public class java1public static void main(string args)int sum;_;int arrayLis=new int20;for(int i=0;i=19;i+)arrayListi=i+1;int pos=0;while(pos20)if(_)sum-sum+arrayListpos;_;Syste

2、m.out.println(“sum=“+sum);(分数:30.00)_二、简单应用题(总题数:1,分数:40.00)2.本题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“Metal”、“Motif”和“Windows”,单击任何一个按钮,就能将窗口的风格改变为按钮名称所对应的风格。import java.awt.*;import java.awt.event.*;import javax.swing.*;class PlafPanel extends JPanei implements ActionListenerpublic_()metalButton=new JButton

3、(“Metal“);motifButton=new JButton(“Motif“);windowsButton=new JButton(“Windows“);add(metalButton);add(motifButton);add(windowsButton);metalButton.addActionListener(this);motifButton.addActionListener(this);windowsButton.addActionListener(this);public void actionPerformed(ActionEvent evt)Object source

4、=evt.getSource();String plaf=“;if(source=metalButton)plaf=“javax.swing.plaf.metal.MetalLookAndFeel“;else if(source=motifButton)plaf=“com.sun.java.swing.plaf.motif.MotifLookAndFeel“;else if(source=windowsButton)plaf=“com.sun.java.swing.plaf.windows.WindowsLookAndFeel“;tryUIManager.setLookAndFeel(_);S

5、wingUtilities.updateComponentTreeUI(this);catch(Exception e)private JButton metalButton;private JButton motifButton;private JButton windowsButton;class PlafFrame extends JFramepublic PlafFrame()setTitle(“simple“);setSize(300,200);addWindowListener(new WindowAdapter()public void windowClosing(WindowE

6、vent e)System.exit(0););Container contentPane=getContentPane();contentPane.add(new PlafPanel();public class java2public static void main(Stringargs)JFrame frame=new PlafFrame();frame.show();(分数:40.00)_三、综合应用题(总题数:1,分数:30.00)3.本程序的功能是获取文本框中的文本。窗口中有两个文本框“用户名”和“密码”,以及三个按钮“登录”、“其他用户登录”和“关闭”,初始状态“用户名”文本框

7、是只读的,单击“其他用户登录”按钮后变成可写的,“密码”文本框使用的不是密码文本框,在用户键入的时候设置显示为*号。输入用户名和密码后,单击“登录”按钮后,如果输入的密码为空,则弹出提示消息框,否则后台将显示输入的用户名和密码。比如显示为“admin 用户的密码:password”(admin 为输入的用户名,password 为输入密码)。import java.awt.*;import java.awt.event.*;import javax.swing.JOptionPane;public class java3public static void main(String args)f

8、inal Frame frmFrame=new Frame();Panel pnlPanel=new Panel();Label lblUsername=new Label(“用户名“);Label lblPassword=new Label(“密码“);final TextField txtUsername=new TextField(“Student“);final TextField txtPassword=new TextField(“.8);txtUsername.setEditable(false);txtPassword.setChar(*);Button btnButton1=

9、new Button(“登录“);Button btnButton2=new Button(“其他用户登录“);Button btnButton3=new Button(“关闭“);btnButton1.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)if(txtPassword.getText().length()=0)JOptionPane.showMessageDialog(frmFrame,“密码不能为空“);return;txtPassword.setColumns(16)

10、;System.out.println(txtUsername.getText()+“用户的密码:“+txtPassword.getPassword(););btnButton2.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)txtUsername.setEnable(true););btnButton3.addActionListener(new ActionListener()public void aetionPerformed(ActionEvent e)System.ex

11、it(0););pnlPanel.add(lblUsername);pnlPanel.add(txtUsername);pnlPanel.add(lblPassword);pnlPanel.add(txtPassword);pnlPanel.add(btnButtonl);pnlPanel.add(btnButton2);pnlPanel.add(btnButton3);frmFrame.add(pnlPanel);frmFrame.setTitle(“advance“);frmFrame.pack();frmFrame.show();(分数:30.00)_二级 JAVA 机试-69 答案解析

12、(总分:100.00,做题时间:90 分钟)一、基本操作题(总题数:1,分数:30.00)1.本题中定义了一个长度为 20 的整数数组,然后将 120 分别赋给数组元素,计算该数组中所有下标为奇数的元素的和。public class java1public static void main(string args)int sum;_;int arrayLis=new int20;for(int i=0;i=19;i+)arrayListi=i+1;int pos=0;while(pos20)if(_)sum-sum+arrayListpos;_;System.out.println(“sum=

13、“+sum);(分数:30.00)_正确答案:(第 1 处:sum=0第 2 处:pos%2=1 或 pos%2!=0第 3 处:pos+或 pos+=1 或 pos=pos+1)解析:解析 第 1 处给整型变量 sum 赋初值;第 2 处为判断数组中元素下标为奇数的条件;第 3 处是元素下标加 1 继续遍历。二、简单应用题(总题数:1,分数:40.00)2.本题的功能是通过按钮来选择窗口显示的风格。窗口中有三个按钮:“Metal”、“Motif”和“Windows”,单击任何一个按钮,就能将窗口的风格改变为按钮名称所对应的风格。import java.awt.*;import java.aw

14、t.event.*;import javax.swing.*;class PlafPanel extends JPanei implements ActionListenerpublic_()metalButton=new JButton(“Metal“);motifButton=new JButton(“Motif“);windowsButton=new JButton(“Windows“);add(metalButton);add(motifButton);add(windowsButton);metalButton.addActionListener(this);motifButton.

15、addActionListener(this);windowsButton.addActionListener(this);public void actionPerformed(ActionEvent evt)Object source=evt.getSource();String plaf=“;if(source=metalButton)plaf=“javax.swing.plaf.metal.MetalLookAndFeel“;else if(source=motifButton)plaf=“com.sun.java.swing.plaf.motif.MotifLookAndFeel“;

16、else if(source=windowsButton)plaf=“com.sun.java.swing.plaf.windows.WindowsLookAndFeel“;tryUIManager.setLookAndFeel(_);SwingUtilities.updateComponentTreeUI(this);catch(Exception e)private JButton metalButton;private JButton motifButton;private JButton windowsButton;class PlafFrame extends JFramepubli

17、c PlafFrame()setTitle(“simple“);setSize(300,200);addWindowListener(new WindowAdapter()public void windowClosing(WindowEvent e)System.exit(0););Container contentPane=getContentPane();contentPane.add(new PlafPanel();public class java2public static void main(Stringargs)JFrame frame=new PlafFrame();fram

18、e.show();(分数:40.00)_正确答案:(第 1 处:PlafPanel第 2 处:plaf)解析:解析 第一处由题意可知,类 PlafPanel 缺少构造函数,所以填 PlafPanel。第二处是通过String 类型的对象 plaf,和 UIManager.setLookAndFeel()方法实现显示风格的切换。三、综合应用题(总题数:1,分数:30.00)3.本程序的功能是获取文本框中的文本。窗口中有两个文本框“用户名”和“密码”,以及三个按钮“登录”、“其他用户登录”和“关闭”,初始状态“用户名”文本框是只读的,单击“其他用户登录”按钮后变成可写的,“密码”文本框使用的不是密

19、码文本框,在用户键入的时候设置显示为*号。输入用户名和密码后,单击“登录”按钮后,如果输入的密码为空,则弹出提示消息框,否则后台将显示输入的用户名和密码。比如显示为“admin 用户的密码:password”(admin 为输入的用户名,password 为输入密码)。import java.awt.*;import java.awt.event.*;import javax.swing.JOptionPane;public class java3public static void main(String args)final Frame frmFrame=new Frame();Panel

20、 pnlPanel=new Panel();Label lblUsername=new Label(“用户名“);Label lblPassword=new Label(“密码“);final TextField txtUsername=new TextField(“Student“);final TextField txtPassword=new TextField(“.8);txtUsername.setEditable(false);txtPassword.setChar(*);Button btnButton1=new Button(“登录“);Button btnButton2=ne

21、w Button(“其他用户登录“);Button btnButton3=new Button(“关闭“);btnButton1.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)if(txtPassword.getText().length()=0)JOptionPane.showMessageDialog(frmFrame,“密码不能为空“);return;txtPassword.setColumns(16);System.out.println(txtUsername.getTe

22、xt()+“用户的密码:“+txtPassword.getPassword(););btnButton2.addActionListener(new ActionListener()public void actionPerformed(ActionEvent e)txtUsername.setEnable(true););btnButton3.addActionListener(new ActionListener()public void aetionPerformed(ActionEvent e)System.exit(0););pnlPanel.add(lblUsername);pnl

23、Panel.add(txtUsername);pnlPanel.add(lblPassword);pnlPanel.add(txtPassword);pnlPanel.add(btnButtonl);pnlPanel.add(btnButton2);pnlPanel.add(btnButton3);frmFrame.add(pnlPanel);frmFrame.setTitle(“advance“);frmFrame.pack();frmFrame.show();(分数:30.00)_正确答案:(第 1 处:txtPassword.setEchoChar(*)第 2 处:txtPassword.getText()第 3 处:txtUsername.setEditable(true)解析:解析 第一处是通过 TextField 类的 setEchoChar 函数设置用户输入时,文本框显示的文本。第二处是通过 TextField 类的 getText 函数获取用户的输入,即得到密码值。第三处是使用户名文本框变为可用,使用户可以输入。

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