




已阅读5页,还剩22页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Lake Rothschild 疯狂源自梦想 lake Rothschild 第 1 1 页 雷克 共 2727 页 JavaJava 开发实战经典课后答案 By 雷克 第三章 第一题 打印 1 1000 范围内的水仙花数 水仙花数是指一个三位数 其各位数 字的立方和等于该数本身 第四题 判断三个数同时能被 3 5 7 整除 第五题 分别利用 while 循环 do while 循环和 for 循环求出 100 200 的累加 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 2 2 页 雷克 共 2727 页 第六题 编写程序 求 13 23 33 44 973 983 993 1003 的值 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 3 3 页 雷克 共 2727 页 第十题 求 1 1000 之间能同时被 3 5 7 整除的数并统计一共有多少个数字 第十一题 编程求 1 2 3 20 的值 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 4 4 页 雷克 共 2727 页 第十二题 使用 for 循环打印一下图案 第四章 第一题 编写程序求 1 2 30 的和并显示 要求用方法完成 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 5 5 页 雷克 共 2727 页 第二题 定义一个由整数组成的数组 统计其中奇数和偶数的个数 第三题 现在有如下的数组 int oldArr 2 3 5 0 7 0 5 9 4 0 23 0 将其中不为 0 的 值存入一个新的数组 新生成的数组为 int oldArr 2 3 5 7 5 9 4 23 第四题 一定一个整型数组 求出数组元素的和 数组元素的最大值和最小值 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 6 6 页 雷克 共 2727 页 并输出所求的结果 第五题 给出 10 个整型数 然后任意查询一个数字是否存在该 10 个数字之内 第六题 定义一个包含 10 个元素的数组 对其进行赋值 使每个元素的值等于 其下标 然后输出 最后将这个数组倒置 即首尾交换 后输出 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 7 7 页 雷克 共 2727 页 第八题 有 30 个 0 9 之间的数 分别统计 0 9 这 10 个数分别出现了多少次 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 8 8 页 雷克 共 2727 页 第九题 定义一个整型数组 保存 10 个数据 利用程序完成将最大值保存在数 组中第一个元素的操作 第十题 在排序好的数组中添加一个数字 将添加后的数字插入到合适的位置 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 9 9 页 雷克 共 2727 页 第十一题 3 现在给出两个数组 数组 A 1 7 9 11 13 15 17 19 数组 b 2 4 6 8 10 两个数组合并为数组 c 按升序排列 第五章 第三题 编写程序统计出字符串 want you to know one thing 中字母 n 和字母 o 出现的个数 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 1010 页 雷克 共 2727 页 第六题 字符串操作 从字符串 知通团队 JAVA20120909 中提取日期 将 知通团队 JAVA 中的 JAVA 替换成 J2EE 清除 知通团队 java 组 20120909 中所有的 0 清除 安徽理工大学 知通团队 java 组 20120909 中所有的空格 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 1111 页 雷克 共 2727 页 从任意给定的身份证号提取此人的生日 使用正则表达式的方法 第九题 声明一个图书类 其数据成员为 书名 编号 利用静态变量实现自动编号 书 价 并拥有静态数据成员册数 记录图书的总册数 在构造方法中利用此静态变量为对象的 编号赋值 在主方法中定义对象数组 并求出总册数 class Book private String name private int id Lake Rothschild 疯狂源自梦想 lake Rothschild 第 1212 页 雷克 共 2727 页 private float price private static int num 3 private static int count 0 public Book count this id count public Book int id this id id public int getId return this id public Book String name float price this name name this price price this num num public void setName String name this name name public String getName return this name public void setPrice float price this price price public float getPrice return this price public void setNum int num this num num public int getNum return this num public class Lake public static void main String args Book book new Book 6 book 0 new Book java 教程 99 9f book 1 new Book java web 教程 69 9f Lake Rothschild 疯狂源自梦想 lake Rothschild 第 1313 页 雷克 共 2727 页 book 2 new Book java EE 教程 67 9f book 3 new Book android 教程 56 8f book 4 new Book Mysql 教程 56 5f book 5 new Book oracle 教程 78 7f for int i 0 i0 this goods new Goods len else this goods new Goods 1 public boolean add Goods goods if this foot this goods length this goods this foot goods this foot return true else return false public Goods getContent return this goods Lake Rothschild 疯狂源自梦想 lake Rothschild 第 1616 页 雷克 共 2727 页 public Goods search String keyWord Goods g null int count 0 for int i 0 i this goods length i if this goods i null if this goods i getName indexOf keyWord 1 count g new Goods count int f 0 for int i 0 i this goods length i if this goods i null if this goods i getName indexOf keyWord 1 g f this goods i f return g public class Lake public static void main String args ShopCar sc new ShopCar 6 sc add new Books 疯狂 JAVA 69 9f 1 李刚 清华大学出版社 sc add new Books 疯狂 AJAX 79 9f 5 李刚 电子工业出版社 sc add new Books Oracle 实战 99 9f 3 李兴华 清华大学出版社 sc add new Cloths T 恤 109 9f 2 李宁 男式 M sc add new Cloths 牛仔裤 169 9f 2 森马 女士 L sc add new Cloths 衬衫 129 9f 1 杰克琼斯 男式 L System out println 已买到的商品清单 print1 sc getContent System out println 查询商品详细信息 try print sc search args 0 catch Exception e System out println 未输入要查询商品或输入错误 格式为 njava Test 商品名 或商品名中的任意字符 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 1717 页 雷克 共 2727 页 public static void print1 Goods goods for int i 0 i goods length i System out println goods i getInfo1 public static void print Goods goods for int i 0 i goods length i System out println goods i getInfo 第九章 实例设计 设计一个生产电脑和搬运电脑类 要求生产出一台电脑就搬走一台电 脑 如果没有新的电脑产生 则等待新的电脑产生才能搬运 如果电脑没有搬走 则不能生 产新的电脑 最后统计生产出来的电脑的数量 package lake class Computer private int count 0 private String name null private String style null private boolean flag false public void setName String name this name name public void setStyle String style this style style public String getName return this name public String getStyle return this style public synchronized void set String name String style if flag try super wait catch Exception e e printStackTrace this setName name Lake Rothschild 疯狂源自梦想 lake Rothschild 第 1818 页 雷克 共 2727 页 try Thread sleep 100 catch Exception e e printStackTrace this setStyle style System out println Thread currentThread getName this getName this getStyle flag true super notify public synchronized void get if flag try super wait catch Exception e e printStackTrace try Thread sleep 500 catch Exception e e printStackTrace System out println Thread currentThread getName this getName this getStyle flag false super notify count public void say System out println 货取完了 总计 count 台 class Made implements Runnable private Computer computer null public Made Computer computer puter computer public void run boolean flag false for int i 1 i 1 i try Thread sleep 100 catch Exception e e printStackTrace if i 0 puter get else puter say public class Lake public static void main String args Computer c new Computer Made ma new Made c Move mo new Move c new Thread ma 生产部生产出 start new Thread mo 物流取走 start 第十章 实例设计 按照要求定义一个操作类 要求完成一个一维数组操作类 其中可以 加入任意类型的数据 数据的具体操作类型由程序外部决定 并可以实现查询功能 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 2020 页 雷克 共 2727 页 第十一章 第一题 定义一个 StringBuffer 类对象 然后通过 append 方法向对象中添加 26 个小写字母 要求每次只能添加一个 共添加 26 次 然后按照逆序的方式输出 并可以删除前 5 个字符 第三题 输入一个 Email 地址 然后使用正则表达式判断其是否正确 第五题 编写正则表达式 判断给定的是否是一个合法的 IP 地址 第六题 给定下面的 HTML 代码 要求对内容 进行拆分 拆分之后的结果是 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 2121 页 雷克 共 2727 页 face Arial Serif size 2 color red 第七题 编写程序 实现国际化应用 从命令行输入国家的代号 如 1 表示中国 2 表示 美国 3 表示法国 然后根据输入的代号不同调用不同的文件资源显示信息 另外需要注意的是 需要在 calss 文件所在位置配上各国的属性文件 第八题 参照 java 实战经典 383 页 第十二章 第七题 完成登录系统 从命令行输入用户名和密码 当没有输入用户名或 密码的时候提醒输入用户名和密码 让用户继续输入 若正确则显示登录成功信息 失败则 显示登录失败信息 如果连续 3 次输入密码错误则退出系统 import java util Scanner class Operate public void check Scanner s new Scanner System in boolean flag true int count 0 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 2222 页 雷克 共 2727 页 int num 0 while flag System out print 请输入用户名 String str s next if str null System out println 用户名不能为空 flag true else if str equals lake System out print 请输入密码 String str2 s next if str2 null System out println 密码不能为空 flag true else if str2 equals lxq System out println 登录成功 flag false else System out println 密码错误 登录失败 count if count 3 System out println 密码输入 3 次错误 n 系统退出 System exit 1 else System out println 用户名不存在 请重新输入 flag true num if num 3 System out println 用户名 3 次输入错误 n 系统退出 System exit 1 public class Lake public static void main String args Operate p new Operate Lake Rothschild 疯狂源自梦想 lake Rothschild 第 2323 页 雷克 共 2727 页 p check 第十题 实例设计 设计统计投票器 A 功能描述 功能描述 有一个班采用民主投票方法推选班长 班长候选人共 4 位 每个人姓名及代号分别为 张三 1 李四 2 王五 3 刘六 4 程序操作员将每张选票上所填的代号 1 2 3 或 4 循环输入电脑 输入数字 0 结束输入 然后将所有候选人的得票情况显示出来 并显示最终当选者的信息 B 具体要求如下 具体要求如下 1 编写候选人类 Person 将候选人姓名 代号和票数保存到类 Person 候选人类 中 2 输入数据之前 显示出各位候选人的代号及姓名 提示 建立一个候选人类型数组 如下所示 3 循环执行接收键盘输入的班长候选人代号 直到输入的数字为 0 结束选票的输入工作 如下图所 示 4 在接收每次输入的选票后要求验证该选票是否有效 即 如果输入的数不是 0 1 2 3 4 这 5 个 数字之一 或者输入一串字母 捕捉异常 应显示出错误提示信息 此选票无效 请输入正确的候选人代 号 并继续等待输入 5 输入结束后显示所有候选人的得票情况 如下所示 6 输出最终当选者的相关信息 如下所示 C 参考图示 参考图示 1 张三 0票 2 李四 0票 3 王五 0票 4 刘六 0票 请输入班长候选人代号 数字0结束 1 请输入班长候选人代号 数字0结束 1 请输入班长候选人代号 数字0结束 1 请输入班长候选人代号 数字0结束 1 请输入班长候选人代号 数字0结束 2 请输入班长候选人代号 数字0结束 3 请输入班长候选人代号 数字0结束 4 请输入班长候选人代号 数字0结束 5 此选票无效 请输入正确的候选人代号 请输入班长候选人代号 数字0结束 hello 此选票无效 请输入正确的候选人代号 请输入班长候选人代号 数字0结束 0 1 张三 4票 2 李四 1票 3 王五 1票 4 刘六 1票 投票最终结果 张三同学 最后以4票当选班长 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 2424 页 雷克 共 2727 页 先定义 Person 类 Person java package candidate public class Person implements Comparable private String name private int id private int count public Person super public Person int id String name int count super this name name this id id this count count public String getName return name public void setName String name this name name public int getId return id public void setId int id this id id public int getCount return count public void setCount int count this count count public int compareTo Person p if this count p count return 1 else if this count p count return 1 else return 0 Lake Rothschild 疯狂源自梦想 lake Rothschild 第 2525 页 雷克 共 2727 页 然后定义专门处理从键盘接收数据的类 InputData java package candidate import java io BufferedReader import java io IOException import java io InputStreamReader public class InputData InputStreamReader input new InputStreamReader System in BufferedReader buf new BufferedReader input public int getInt String msg String err int num 0 boolean flag true while flag System out println msg String str try str this buf readLine catch IOException e TODO Auto generated catch block e printStackTrace if str matches d num Integer parseInt str flag false else System out println err return num 然后定义操作类 Operate java package candidate public class Operate private Person per new Person new Person 1 赵一 0 new Person 2 钱二 0 new Person 3 孙三 0 new Person 4 李四 0 new Person 5 周五 0 new Person 6 五六 0 private InputData input new InputData privat
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年江西省交通投资集团有限责任公司社会招聘17人笔试参考题库附带答案详解
- 2025年山东菏泽市通达协合劳务有限公司招聘劳务派遣制人员8人笔试参考题库附带答案详解
- 2025年国网直流中心高校毕业生招聘(第二批)调剂笔试参考题库附带答案详解
- 卸沙作业安全培训课件
- 2025山西焦煤“‘企’聚人才‘职’等你来”省属企业专场招聘会招聘300人笔试参考题库附带答案详解
- 2025山东电工电气集团招聘50人笔试参考题库附带答案详解
- 2025安徽安庆市桐城经开区建设投资集团有限公司招聘12人笔试参考题库附带答案详解
- 2025国家电投山西公司招聘若干人笔试参考题库附带答案详解
- 2025上半年上海闵行区区管国企公开招聘35人笔试参考题库附带答案详解
- 地铁新员工安全培训心得
- 康复伦理问题
- 配位化学-本科生版智慧树知到答案章节测试2023年兰州大学
- 华北电力大学授予本科生学士学位名单
- 学生休学证明模板
- 机电安装工程技术标书(模板)
- 无机及分析化学第2章-化学热力学基础1
- GB/T 2930.1-2017草种子检验规程扦样
- 会计学原理模拟试题一套
- 第一章-宗教社会学的发展和主要理论范式课件
- 国内外新能源现状及发展趋势课件
- 高速公路改扩建桥梁拼宽施工技术及质量控制
评论
0/150
提交评论