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

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

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 函数获取用户的输入,即得到密码值。第三处是使用户名文本框变为可用,使用户可以输入。

展开阅读全文
相关资源
猜你喜欢
  • TCVN 7446-2-2004 Steels Classification Part 2 Classification of unalloyed and alloy steels according to main quality classes and main property or application characteristics《钢 分类 第.pdf TCVN 7446-2-2004 Steels Classification Part 2 Classification of unalloyed and alloy steels according to main quality classes and main property or application characteristics《钢 分类 第.pdf
  • TCVN 7447-1-2010 Low-voltage electrical installations Part 1 Fundamental principles assessment of general characteristics definitions《低压电气设施 第1部分 基本原则 一般特性评价和定义》.pdf TCVN 7447-1-2010 Low-voltage electrical installations Part 1 Fundamental principles assessment of general characteristics definitions《低压电气设施 第1部分 基本原则 一般特性评价和定义》.pdf
  • TCVN 7447-4-41-2010 Low-voltage electrical installations Part 4-41 Protection for safety Protection against electric shock《低压电气设施 第4-41部分 安全防护 电击防护》.pdf TCVN 7447-4-41-2010 Low-voltage electrical installations Part 4-41 Protection for safety Protection against electric shock《低压电气设施 第4-41部分 安全防护 电击防护》.pdf
  • TCVN 7447-4-42-2005 Electrical installations of buildings Part 4-42 Protection for safety Protection against thermal effects《建筑物电气装置 第4-42部分 安全防护 热效应防护》.pdf TCVN 7447-4-42-2005 Electrical installations of buildings Part 4-42 Protection for safety Protection against thermal effects《建筑物电气装置 第4-42部分 安全防护 热效应防护》.pdf
  • TCVN 7447-4-43-2010 Low-voltage electrical installations Part 4-43 Protection for safety Protection against overcurrent《低压电气设施 第4-43部分 安全防护 过电流防护》.pdf TCVN 7447-4-43-2010 Low-voltage electrical installations Part 4-43 Protection for safety Protection against overcurrent《低压电气设施 第4-43部分 安全防护 过电流防护》.pdf
  • TCVN 7447-4-44-2010 Low-voltage electrical installations Part 4-44 Protection for safety Protection against voltage disturbances and electromagnetic disturbances《低压电气设施 第4-44部分 安全防.pdf TCVN 7447-4-44-2010 Low-voltage electrical installations Part 4-44 Protection for safety Protection against voltage disturbances and electromagnetic disturbances《低压电气设施 第4-44部分 安全防.pdf
  • TCVN 7447-5-51-2010 Electrical installations of buildings Part 5-51 Selection and erection of electrical equipment Common rules《建筑物电气装置 第5-51部分 电气设备的选择和安装 一般规则》.pdf TCVN 7447-5-51-2010 Electrical installations of buildings Part 5-51 Selection and erection of electrical equipment Common rules《建筑物电气装置 第5-51部分 电气设备的选择和安装 一般规则》.pdf
  • TCVN 7447-5-52-2010 Low-voltage electrical installations Part 5-52 Selection and erection of electrical equipment Wiring systems《低压电气设施 第5-52部分 电气设备的选择和安装 布线系统》.pdf TCVN 7447-5-52-2010 Low-voltage electrical installations Part 5-52 Selection and erection of electrical equipment Wiring systems《低压电气设施 第5-52部分 电气设备的选择和安装 布线系统》.pdf
  • TCVN 7447-5-53-2005 Electrical installations of buildings Part 5-53 Selection and erection of electrical equipment Isolation switching and control《建筑物电气装置 第5-53部分 电气设备的选择和安装 绝缘 开关设.pdf TCVN 7447-5-53-2005 Electrical installations of buildings Part 5-53 Selection and erection of electrical equipment Isolation switching and control《建筑物电气装置 第5-53部分 电气设备的选择和安装 绝缘 开关设.pdf
  • 相关搜索
    资源标签

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

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