`
pThink
  • 浏览: 650 次
社区版块
存档分类
最新评论
阅读更多

第五届全国ITAT教育工程就业技能大赛复赛试题
Java程序设计(A卷)

<!--[if !supportLists]-->1、  <!--[endif]-->某人有53分和45分的邮票,请编写一个程序,计算由这些邮票中的1张或若干张可以得到多少种不同的邮资,并按照邮资从小到大顺序显示。(20分)

 

<!--[if !supportLists]-->2、  <!--[endif]-->采用Java多线程技术编写程序,其中包括两个线程:AB,其中A线程准备休眠一小时,B线程每隔一秒输入3句“起床”后,吵醒休眠的线程A。(25分)

 

<!--[if !supportLists]-->3、  <!--[endif]-->利用JavaGUI编程,编写一个窗体,包含两个文本框和一个命令按钮。其中一个文本框接收用户输入的一行字符串,回车后在另一个文本框中重复输出三行,单击命令按钮可清空两个文本框的所有内容。(25分)

 

<!--[if !supportLists]-->4、  <!--[endif]-->编写一个Java应用程序,运行后,首先列出当前工作目录,然后把当前目录下面的所有后缀为java的文件取出(设置一个过滤器进行文件名后缀的过滤)。(30分)

 

答案:

 

第一题:

<!--[if !supportLists]-->1.  <!--[endif]-->package exercise1;  

<!--[if !supportLists]-->2.  <!--[endif]-->  

<!--[if !supportLists]-->3.  <!--[endif]-->import java.util.ArrayList;  

<!--[if !supportLists]-->4.  <!--[endif]-->import java.util.Arrays;  

<!--[if !supportLists]-->5.  <!--[endif]-->import java.util.HashSet;  

<!--[if !supportLists]-->6.  <!--[endif]-->import java.util.Iterator;  

<!--[if !supportLists]-->7.  <!--[endif]-->  

<!--[if !supportLists]-->8.  <!--[endif]-->public class PostCount {  

<!--[if !supportLists]-->9.  <!--[endif]-->  

<!--[if !supportLists]-->10. <!--[endif]-->    /** 

<!--[if !supportLists]-->11. <!--[endif]-->     * @param args 

<!--[if !supportLists]-->12. <!--[endif]-->     */  

<!--[if !supportLists]-->13. <!--[endif]-->    public static void main(String[] args) {  

<!--[if !supportLists]-->14. <!--[endif]-->        int count = 0;  

<!--[if !supportLists]-->15. <!--[endif]-->        HashSet<Integer> post = new HashSet<Integer>();  

<!--[if !supportLists]-->16. <!--[endif]-->        for (int i = 0; i < 6; i++)  

<!--[if !supportLists]-->17. <!--[endif]-->            for (int j = 0; j < 5; j++) {  

<!--[if !supportLists]-->18. <!--[endif]-->                count = i * 3 + j * 5;  

<!--[if !supportLists]-->19. <!--[endif]-->                post.add(new Integer(count));  

<!--[if !supportLists]-->20. <!--[endif]-->            }  

<!--[if !supportLists]-->21. <!--[endif]-->        post.remove(new Integer(0));  

<!--[if !supportLists]-->22. <!--[endif]-->        Iterator<Integer> it = post.iterator();  

<!--[if !supportLists]-->23. <!--[endif]-->        ArrayList<Integer> al = new ArrayList<Integer>();  

<!--[if !supportLists]-->24. <!--[endif]-->        while (it.hasNext()) {  

<!--[if !supportLists]-->25. <!--[endif]-->            al.add((Integer) it.next());  

<!--[if !supportLists]-->26. <!--[endif]-->        }  

<!--[if !supportLists]-->27. <!--[endif]-->        post.clear();  

<!--[if !supportLists]-->28. <!--[endif]-->        int b[] = new int[al.size()];  

<!--[if !supportLists]-->29. <!--[endif]-->        for (int i = 0; i < al.size(); i++) {  

<!--[if !supportLists]-->30. <!--[endif]-->            b[i] = (new Integer(al.get(i))).intValue();  

<!--[if !supportLists]-->31. <!--[endif]-->        }  

<!--[if !supportLists]-->32. <!--[endif]-->        al.clear();  

<!--[if !supportLists]-->33. <!--[endif]-->        Arrays.sort(b);  

<!--[if !supportLists]-->34. <!--[endif]-->        System.out.println(Arrays.toString(b));  

<!--[if !supportLists]-->35. <!--[endif]-->  

<!--[if !supportLists]-->36. <!--[endif]-->    }  

<!--[if !supportLists]-->37. <!--[endif]-->  

<!--[if !supportLists]-->38. <!--[endif]-->

 

 

 

第二题:

<!--[if !supportLists]-->1.  <!--[endif]-->package thread;  

<!--[if !supportLists]-->2.  <!--[endif]-->  

<!--[if !supportLists]-->3.  <!--[endif]-->public class Itat_2_thread {  

<!--[if !supportLists]-->4.  <!--[endif]-->    public final static Thread t1 = new SleepThread();  

<!--[if !supportLists]-->5.  <!--[endif]-->    public static void main(String[] args) {  

<!--[if !supportLists]-->6.  <!--[endif]-->        Thread t2 = new Thread("wake_up") {  

<!--[if !supportLists]-->7.  <!--[endif]-->            public void run() {  

<!--[if !supportLists]-->8.  <!--[endif]-->                while (true) {  

<!--[if !supportLists]-->9.  <!--[endif]-->                    try {  

<!--[if !supportLists]-->10. <!--[endif]-->                        Thread.sleep(1000);  

<!--[if !supportLists]-->11. <!--[endif]-->                        for (int i = 0; i < 3; i++)  

<!--[if !supportLists]-->12. <!--[endif]-->                            System.out.println("起床");  

<!--[if !supportLists]-->13. <!--[endif]-->                        synchronized (t1) {  

<!--[if !supportLists]-->14. <!--[endif]-->                            t1.interrupt();  

<!--[if !supportLists]-->15. <!--[endif]-->                        }//同步代码块  

<!--[if !supportLists]-->16. <!--[endif]-->                    } catch (InterruptedException e) {  

<!--[if !supportLists]-->17. <!--[endif]-->                        // TODO Auto-generated catch block  

<!--[if !supportLists]-->18. <!--[endif]-->                        e.printStackTrace();  

<!--[if !supportLists]-->19. <!--[endif]-->                    }  

<!--[if !supportLists]-->20. <!--[endif]-->                }  

<!--[if !supportLists]-->21. <!--[endif]-->            }  

<!--[if !supportLists]-->22. <!--[endif]-->        };  

<!--[if !supportLists]-->23. <!--[endif]-->        t1.start();  

<!--[if !supportLists]-->24. <!--[endif]-->        t2.start();  

<!--[if !supportLists]-->25. <!--[endif]-->    }  

<!--[if !supportLists]-->26. <!--[endif]-->}  

<!--[if !supportLists]-->27. <!--[endif]-->  

<!--[if !supportLists]-->28. <!--[endif]-->class SleepThread extends Thread {  

<!--[if !supportLists]-->29. <!--[endif]-->    public void run() {  

<!--[if !supportLists]-->30. <!--[endif]-->        while (true) {  

<!--[if !supportLists]-->31. <!--[endif]-->            try {  

<!--[if !supportLists]-->32. <!--[endif]-->                Thread.sleep(1000 * 60 * 60);  

<!--[if !supportLists]-->33. <!--[endif]-->            } catch (InterruptedException e) {  

<!--[if !supportLists]-->34. <!--[endif]-->                System.out.println("吵醒休眠线程A");  

<!--[if !supportLists]-->35. <!--[endif]-->                // do what you want after the thread are waked up  

<!--[if !supportLists]-->36. <!--[endif]-->            }  

<!--[if !supportLists]-->37. <!--[endif]-->        }  

<!--[if !supportLists]-->38. <!--[endif]-->    }  

<!--[if !supportLists]-->39. <!--[endif]-->}

 

 

第三题:

<!--[if !supportLists]-->1.  <!--[endif]-->package sugite.swing;  

<!--[if !supportLists]-->2.  <!--[endif]-->  

<!--[if !supportLists]-->3.  <!--[endif]-->import java.awt.Event;  

<!--[if !supportLists]-->4.  <!--[endif]-->import java.awt.GridLayout;  

<!--[if !supportLists]-->5.  <!--[endif]-->import java.awt.event.KeyAdapter;  

<!--[if !supportLists]-->6.  <!--[endif]-->import java.awt.event.KeyEvent;  

<!--[if !supportLists]-->7.  <!--[endif]-->import java.awt.event.MouseAdapter;  

<!--[if !supportLists]-->8.  <!--[endif]-->import java.awt.event.MouseEvent;  

<!--[if !supportLists]-->9.  <!--[endif]-->import java.awt.event.WindowAdapter;  

<!--[if !supportLists]-->10. <!--[endif]-->import java.awt.event.WindowEvent;  

<!--[if !supportLists]-->11. <!--[endif]-->  

<!--[if !supportLists]-->12. <!--[endif]-->import javax.swing.JButton;  

<!--[if !supportLists]-->13. <!--[endif]-->import javax.swing.JFrame;  

<!--[if !supportLists]-->14. <!--[endif]-->import javax.swing.JTextArea;  

<!--[if !supportLists]-->15. <!--[endif]-->import javax.swing.JTextField;  

<!--[if !supportLists]-->16. <!--[endif]-->  

<!--[if !supportLists]-->17. <!--[endif]-->public class Itat_3_ans extends JFrame {  

<!--[if !supportLists]-->18. <!--[endif]-->  

<!--[if !supportLists]-->19. <!--[endif]-->    /** 

<!--[if !supportLists]-->20. <!--[endif]-->     *  

<!--[if !supportLists]-->21. <!--[endif]-->     */  

<!--[if !supportLists]-->22. <!--[endif]-->    private static final long serialVersionUID = 1L;  

<!--[if !supportLists]-->23. <!--[endif]-->    static JTextField jt1;  

<!--[if !supportLists]-->24. <!--[endif]-->    static JTextArea jt2;  

<!--[if !supportLists]-->25. <!--[endif]-->    static JButton jb;  

<!--[if !supportLists]-->26. <!--[endif]-->  

<!--[if !supportLists]-->27. <!--[endif]-->    public static void main(String[] args) {  

<!--[if !supportLists]-->28. <!--[endif]-->        JFrame frame = new JFrame();  

<!--[if !supportLists]-->29. <!--[endif]-->        frame.setSize(500500);  

<!--[if !supportLists]-->30. <!--[endif]-->        frame.setLocation(200200);  

<!--[if !supportLists]-->31. <!--[endif]-->        jt1 = new JTextField();  

<!--[if !supportLists]-->32. <!--[endif]-->        jt2 = new JTextArea();  

<!--[if !supportLists]-->33. <!--[endif]-->        jb = new JButton("命令");  

<!--[if !supportLists]-->34. <!--[endif]-->        jt1.addKeyListener(new KeyAdapter() {  

<!--[if !supportLists]-->35. <!--[endif]-->            public void keyPressed(KeyEvent e) {  

<!--[if !supportLists]-->36. <!--[endif]-->                if (e.getKeyCode() == Event.ENTER) // 按键 执行相应操作;  

<!--[if !supportLists]-->37. <!--[endif]-->                {  

<!--[if !supportLists]-->38. <!--[endif]-->                    String str = jt1.getText();  

<!--[if !supportLists]-->39. <!--[endif]-->                    jt1.setText("");  

<!--[if !supportLists]-->40. <!--[endif]-->                    jt2.append(str+"\n" + str +"\n"+ str);  

<!--[if !supportLists]-->41. <!--[endif]-->                }  

<!--[if !supportLists]-->42. <!--[endif]-->            }  

<!--[if !supportLists]-->43. <!--[endif]-->        });  

<!--[if !supportLists]-->44. <!--[endif]-->        jb.addMouseListener(new MouseAdapter() {  

<!--[if !supportLists]-->45. <!--[endif]-->            public void mouseClicked(MouseEvent e) {  

<!--[if !supportLists]-->46. <!--[endif]-->                jt1.setText("");  

<!--[if !supportLists]-->47. <!--[endif]-->                jt2.setText("");  

<!--[if !supportLists]-->48. <!--[endif]-->            }  

<!--[if !supportLists]-->49. <!--[endif]-->        });  

<!--[if !supportLists]-->50. <!--[endif]-->        frame.add(jt1);  

<!--[if !supportLists]-->51. <!--[endif]-->        frame.add(jt2);  

<!--[if !supportLists]-->52. <!--[endif]-->        frame.add(jb);  

<!--[if !supportLists]-->53. <!--[endif]-->        frame.addWindowListener(new WindowAdapter(){  

<!--[if !supportLists]-->54. <!--[endif]-->            public void windowClosing(WindowEvent e){  

<!--[if !supportLists]-->55. <!--[endif]-->                System.exit(1) ;  

<!--[if !supportLists]-->56. <!--[endif]-->            }  

<!--[if !supportLists]-->57. <!--[endif]-->        } );  

<!--[if !supportLists]-->58. <!--[endif]-->        frame.setLayout(new GridLayout(22));  

<!--[if !supportLists]-->59. <!--[endif]-->        frame.setVisible(true);  

<!--[if !supportLists]-->60. <!--[endif]-->          

<!--[if !supportLists]-->61. <!--[endif]-->  

<!--[if !supportLists]-->62. <!--[endif]-->    }  

<!--[if !supportLists]-->63. <!--[endif]-->  

<!--[if !supportLists]-->64. <!--[endif]-->}

 

 

 

 

 

 

 

 

]

 

 

 

 

 

 

 

 

 

 

 

第四题:

<!--[if !supportLists]-->1.  <!--[endif]-->package file_operation;  

<!--[if !supportLists]-->2.  <!--[endif]-->  

<!--[if !supportLists]-->3.  <!--[endif]-->import java.io.File;  

<!--[if !supportLists]-->4.  <!--[endif]-->import java.io.FilenameFilter;  

<!--[if !supportLists]-->5.  <!--[endif]-->public class Itat_4_ans  

<!--[if !supportLists]-->6.  <!--[endif]-->{  

<!--[if !supportLists]-->7.  <!--[endif]-->    public static void main(String[] args)   

<!--[if !supportLists]-->8.  <!--[endif]-->    {  

<!--[if !supportLists]-->9.  <!--[endif]-->        File file = new File("Itat_4_ans.java");  

<!--[if !supportLists]-->10. <!--[endif]-->        String path = file.getAbsolutePath();  

<!--[if !supportLists]-->11. <!--[endif]-->        System.out.println(path);  

<!--[if !supportLists]-->12. <!--[endif]-->        String work_dir = path.substring(0,path.length() - file.toString().length());  

<!--[if !supportLists]-->13. <!--[endif]-->        System.out.println(work_dir);  

<!--[if !supportLists]-->14. <!--[endif]-->        PrintDirJava(new File(work_dir));  

<!--[if !supportLists]-->15. <!--[endif]-->    }  

<!--[if !supportLists]-->16. <!--[endif]-->  

<!--[if !supportLists]-->17. <!--[endif]-->    public static void PrintDirJava(File ff){  

<!--[if !supportLists]-->18. <!--[endif]-->        File f[] = ff.listFiles() ;  

<!--[if !supportLists]-->19. <!--[endif]-->        FileNameFilter fnf = new FileNameFilter();  

<!--[if !supportLists]-->20. <!--[endif]-->        for(int i  = 0 ; i<f.length ; i++){  

<!--[if !supportLists]-->21. <!--[endif]-->            if(fnf.accept(f[i],null))  

<!--[if !supportLists]-->22. <!--[endif]-->                System.out.println(f[i].getName());  

<!--[if !supportLists]-->23. <!--[endif]-->        }  

<!--[if !supportLists]-->24. <!--[endif]-->    }  

<!--[if !supportLists]-->25. <!--[endif]-->}  

<!--[if !supportLists]-->26. <!--[endif]-->  

<!--[if !supportLists]-->27. <!--[endif]-->class FileNameFilter implements FilenameFilter  

<!--[if !supportLists]-->28. <!--[endif]-->{  

<!--[if !supportLists]-->29. <!--[endif]-->    public boolean accept(File pathname,String b) {  

<!--[if !supportLists]-->30. <!--[endif]-->        String files = pathname.toString();        

<!--[if !supportLists]-->31. <!--[endif]-->        if (files.endsWith(".java"))   

<!--[if !supportLists]-->32. <!--[endif]-->            return true;        

<!--[if !supportLists]-->33. <!--[endif]-->        return false;  

<!--[if !supportLists]-->34. <!--[endif]-->    }  

<!--[if !supportLists]-->35. <!--[endif]-->

分享到:
评论

相关推荐

    JAVA_API1.6文档(中文)

    java.lang.management 提供管理接口,用于监视和管理 Java 虚拟机以及 Java 虚拟机在其上运行的操作系统。 java.lang.ref 提供了引用对象类,支持在某种程度上与垃圾回收器之间的交互。 java.lang.reflect 提供类...

    java源码包---java 源码 大量 实例

    Applet钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这款实例会对你有所帮助。 Calendar万年历 1个目标文件 EJB 模拟银行ATM流程及操作源代码 6个目标文件,EJB来模拟银行ATM...

    Java 面经手册·小傅哥.pdf

    这是一本以面试题为入口讲解 Java 核心内容的技术书籍,书中内容极力的向你证实代码是对数学逻辑的具体实现。当你仔细阅读书籍时,会发现Java中有大量的数学知识,包括:扰动函数、负载因子、拉链寻址、开放寻址、...

    Java OCR 图像智能字符识别技术,可识别中文

    Java OCR(Optical Character Recognition,光学字符识别)技术是一种计算机视觉领域的应用,它能将图像中的文字转换成可编辑的文本格式。这项技术在各种场景下都有广泛应用,比如文档扫描、车牌识别、发票处理等。...

    Java API文档 中文网页版

    Java API文档是Java开发者的重要参考资料,它包含了Java开发工具包(JDK)中的所有类、接口、方法和常量的详细说明。这份中文网页版的Java API文档为中国的开发者提供了便利,无需通过英文版本来学习和查找API信息,...

    java_011 java 人脸识别完整源代码

    java_011 java 人脸识别完整源代码java_011 java 人脸识别完整源代码java_011 java 人脸识别完整源代码java_011 java 人脸识别完整源代码java_011 java 人脸识别完整源代码java_011 java 人脸识别完整源代码java_011...

    java源码包2

    Applet钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能。编辑音乐软件的朋友,这款实例会对你有所帮助。 Calendar万年历 1个目标文件 EJB 模拟银行ATM流程及操作源代码 6个目标文件,EJB来模拟银行...

    java电商源代码 java电商源代码

    java电商源代码java电商源代码java电商源代码java电商源代码java电商源代码java电商源代码java电商源代码java电商源代码java电商源代码java电商源代码java电商源代码java电商源代码java电商源代码java电商源代码java...

    java源码包实例源码JAVA开发源码50个合集.zip

    java源码包实例源码JAVA开发源码50个合集: Ajax框架 ZK.rar Java图书馆管理系统源程序.rar Java图片倒影效果实例源码.rar Java图片翻折,将图像压扁.rar Java坦克大战网络对战版源代码.rar Java声音播放程序源代码....

    java api最新7.0

    JAVA开发人员最新版本7.0 api文档!本文档是 Java Platform Standard Edition 7 的 API !Java 1.7 API的中文帮助文档。 深圳电信培训中心 徐海蛟博士教学用api 7.0中文文档。支持全文检索,在线即时查询。 里面列...

    java单机小游戏.zip

    java单机小游戏java单机小游戏java单机小游戏java单机小游戏 java单机小游戏java单机小游戏java单机小游戏java单机小游戏 java单机小游戏java单机小游戏java单机小游戏java单机小游戏 java单机小游戏java单机小游戏...

    java笔记 java笔记

    ### Java基础知识概述 #### 1. 前言 Java是一种广泛使用的面向对象的编程语言,因其跨平台性、安全性和强大的功能而受到欢迎。Java的设计理念是“一次编写,到处运行”,这意味着编写的Java程序可以在任何安装了...

    java开源包4

    JoSQL(SQLforJavaObjects)为Java开发者提供运用SQL语句来操作Java对象集的能力.利用JoSQL可以像操作数据库中的数据一样对任何Java对象集进行查询,排序,分组。 搜索自动提示 Autotips AutoTips是为解决应用系统对于...

    JAVA上百实例源码以及开源项目源代码

    日历表格面板 [ConfigLine.java] 控制条类 [RoundBox.java] 限定选择控件 [MonthMaker.java] 月份表算法类 [Pallet.java] 调色板,统一配色类 Java扫雷源码 Java生成自定义控件源代码 2个目标文件 Java实现HTTP连接...

    java开源包5

    JoSQL(SQLforJavaObjects)为Java开发者提供运用SQL语句来操作Java对象集的能力.利用JoSQL可以像操作数据库中的数据一样对任何Java对象集进行查询,排序,分组。 搜索自动提示 Autotips AutoTips是为解决应用系统对于...

    Java算法集题大全.zip

    Java算法集题大全Java算法集题大全Java算法集题大全Java算法集题大全Java算法集题大全Java算法集题大全Java算法集题大全Java算法集题大全Java算法集题大全Java算法集题大全Java算法集题大全Java算法集题大全Java算法...

    Java2Pas Java代码转pas代码

    Java2Pas是一个实用工具,主要用于将Java编程语言编写的源代码转换为Pascal语言的等效代码。这个工具对于那些需要在两种语言之间迁移代码或者理解不同编程语言语法的开发者来说非常有价值。Java和Pascal虽然都是面向...

    Java开发技术大全(500个源代码).

    HelloWorldApp.java 第一个用Java开发的应用程序。 firstApplet.java 第一个用Java开发的Applet小程序。 firstApplet.htm 用来装载Applet的网页文件 第2章 示例描述:本章介绍开发Java的基础语法知识。 ...

    从Java菜鸟到专家的资料

    这份名为“从Java菜鸟到专家的资料”的压缩包文件包含了丰富的学习资源,旨在帮助初学者逐步成长为Java领域的专家。以下是对各个文件的详细解读: 1. **J2EE研究文集.chm**:这个文件专注于Java企业级应用开发,...

Global site tag (gtag.js) - Google Analytics