李兴华的java开发实战经典习题大部分答案.docx

上传人:b****6 文档编号:5638753 上传时间:2022-12-29 格式:DOCX 页数:33 大小:363.71KB
下载 相关 举报
李兴华的java开发实战经典习题大部分答案.docx_第1页
第1页 / 共33页
李兴华的java开发实战经典习题大部分答案.docx_第2页
第2页 / 共33页
李兴华的java开发实战经典习题大部分答案.docx_第3页
第3页 / 共33页
李兴华的java开发实战经典习题大部分答案.docx_第4页
第4页 / 共33页
李兴华的java开发实战经典习题大部分答案.docx_第5页
第5页 / 共33页
点击查看更多>>
下载资源
资源描述

李兴华的java开发实战经典习题大部分答案.docx

《李兴华的java开发实战经典习题大部分答案.docx》由会员分享,可在线阅读,更多相关《李兴华的java开发实战经典习题大部分答案.docx(33页珍藏版)》请在冰豆网上搜索。

李兴华的java开发实战经典习题大部分答案.docx

李兴华的java开发实战经典习题大部分答案

Java开发实战经典课后答案

第三章

第一题:

打印1~1000范围内的水仙花数,水仙花数是指一个三位数,其各位数字的立方和等于该数本身。

第四题:

判断三个数同时能被3、5、7整除

第五题:

分别利用while循环、do…while循环和for循环求出100~200的累加

第六题:

编写程序,求13-23+33-44+……973-983+993-1003的值

第十题:

求1~1000之间能同时被3、5、7整除的数并统计一共有多少个数字

第十一题:

编程求:

1!

+2!

+3!

……20!

的值

第十二题:

使用for循环打印一下图案

第四章:

第一题:

编写程序求1!

+2!

+……+30!

的和并显示,要求用方法完成。

第二题:

定义一个由整数组成的数组,统计其中奇数和偶数的个数:

第三题:

现在有如下的数组intoldArr[]={2,3,5,0,7,0,5,9,4,0,23,0},将其中不为0的值存入一个新的数组,新生成的数组为:

intoldArr[]={2,3,5,7,5,9,4,23}

第四题:

一定一个整型数组,求出数组元素的和,数组元素的最大值和最小值,并输出所求的结果。

第五题:

给出10个整型数,然后任意查询一个数字是否存在该10个数字之内

第六题:

定义一个包含10个元素的数组,对其进行赋值,使每个元素的值等于其下标,然后输出,最后将这个数组倒置(即首尾交换)后输出:

第八题:

有30个0~9之间的数,分别统计0~9这10个数分别出现了多少次?

第九题:

定义一个整型数组,保存10个数据,利用程序完成将最大值保存在数组中第一个元素的操作。

第十题:

在排序好的数组中添加一个数字,将添加后的数字插入到合适的位置。

第十一题:

3、现在给出两个数组:

•数组A:

“1,7,9,11,13,15,17,19:

•数组b:

“2,4,6,8,10”两个数组合并为数组c,按升序排列。

第五章:

第三题:

编写程序统计出字符串“wantyoutoknowonething”中字母n和字母o出现的个数

第六题:

字符串操作:

①从字符串“知通团队JAVA20120909”中提取日期

②将“知通团队JAVA”中的JAVA替换成J2EE

④清除“知通团队java组20120909”中所有的0

⑤清除“安徽理工大学知通团队java组20120909”中所有的空格。

⑥从任意给定的身份证号提取此人的生日

使用正则表达式的方法:

第九题:

声明一个图书类,其数据成员为:

书名,编号,(利用静态变量实现自动编号)、书价,并拥有静态数据成员册数,记录图书的总册数,在构造方法中利用此静态变量为对象的编号赋值,在主方法中定义对象数组,并求出总册数。

classBook{

privateStringname;

privateintid;

privatefloatprice;

privatestaticintnum=3;

privatestaticintcount=0;

publicBook(){

count++;

this.id=count;

}

publicBook(intid){

this.id=id;

}

publicintgetId(){

returnthis.id;

}

publicBook(Stringname,floatprice){

this.name=name;

this.price=price;

this.num=num;

}

publicvoidsetName(Stringname){

this.name=name;

}

publicStringgetName(){

returnthis.name;

}

publicvoidsetPrice(floatprice){

this.price=price;

}

publicfloatgetPrice(){

returnthis.price;

}

publicvoidsetNum(intnum){

this.num=num;

}

publicintgetNum(){

returnthis.num;

}

}

publicclassLake{

publicstaticvoidmain(Stringargs[]){

Bookbook[]=newBook[6];

book[0]=newBook("java教程",99.9f);

book[1]=newBook("javaweb教程",69.9f);

book[2]=newBook("javaEE教程",67.9f);

book[3]=newBook("android教程",56.8f);

book[4]=newBook("Mysql教程",56.5f);

book[5]=newBook("oracle教程",78.7f);

for(inti=0;i

System.out.println("编号:

"+newBook().getId()+"\t书名:

"+book[i].getName()+

"\t价格:

"+book[i].getPrice()+"\t数量:

"+book[i].getNum());

}

System.out.println("图书总量为:

"+(newBook().getId()-1)*book[1].getNum());

}

}

第六章:

实例设计:

试用面向对象的思想描述小明去超市买东西的情景

abstractclassGoods{

privateStringname;

privatefloatprice;

privateintcount;

publicGoods(Stringname,floatprice,intcount){

this.setName(name);

this.setPrice(price);

this.setCount(count);

}

publicvoidsetName(Stringname){

this.name=name;

}

publicvoidsetPrice(floatprice){

this.price=price;

}

publicvoidsetCount(intcount){

this.count=count;

}

publicStringgetName(){

returnthis.name;

}

publicfloatgetPrice(){

returnthis.price;

}

publicintgetCount(){

returnthis.count;

}

publicabstractStringgetInfo();

publicStringgetInfo1(){

return"品名:

"+this.getName()+

",单价"+this.getPrice()+",数量:

"+this.getCount();

}

}

classBooksextendsGoods{

privateStringauthor;

privateStringpublish;

publicBooks(Stringname,floatprice,intcount,Stringauthor,Stringpublish){

super(name,price,count);

this.setAuthor(author);

this.setPublish(publish);

}

publicvoidsetAuthor(Stringauthor){

this.author=author;

}

publicStringgetAuthor(){

returnthis.author;

}

publicvoidsetPublish(Stringpublish){

this.publish=publish;

}

publicStringgetPublish(){

returnthis.publish;

}

publicStringgetInfo(){

return"书名:

"+this.getName()+",单价:

"+this.getPrice()+",作者:

"+this.getAuthor()+

",出版社:

"+this.getPublish()+",数量:

"+this.getCount()+

",总价:

"+this.getPrice()*this.getCount();

}

publicStringgetInfo1(){

return"品名:

"+this.getName()+

",单价"+this.getPrice()+",数量:

"+this.getCount();

}

}

classClothsextendsGoods{

privateStringtitle;

privateStringstyle;

publicCloths(Stringname,floatprice,intcount,Stringtitle,Stringstyle){

super(name,price,count);

this.setTitle(title);

this.setStyle(style);

}

publicvoidsetTitle(Stringtitle){

this.title=title;

}

publicStringgetTitle(){

returnthis.title;

}

publicvoidsetStyle(Stringstyle){

this.style=style;

}

publicStringgetStyle(){

returnthis.style;

}

publicStringgetInfo(){

return"品名:

"+this.getName()+",单价:

"+this.getPrice()+

",品牌:

"+this.getTitle()+",款式:

"+this.getStyle()+

",数量:

"+this.getCount()+",总价:

"+this.getPrice()*this.getCount();

}

publicStringgetInfo1(){

return"品名:

"+this.getName()+

",单价"+this.getPrice()+",数量:

"+this.getCount();

}

}

classShopCar{

privateGoods[]goods;

privateintfoot;

publicShopCar(intlen){

if(len>0){

this.goods=newGoods[len];

}else{

this.goods=newGoods[1];

}

}

publicbooleanadd(Goodsgoods){

if(this.foot

this.goods[this.foot]=goods;

this.foot++;

returntrue;

}else{

returnfalse;

}

}

publicGoods[]getContent(){

returnthis.goods;

}

publicGoods[]search(StringkeyWord){

Goodsg[]=null;

intcount=0;

for(inti=0;i

if(this.goods[i]!

=null){

if(this.goods[i].getName().indexOf(keyWord)!

=-1){

count++;

}

}

}

g=newGoods[count];

intf=0;

for(inti=0;i

if(this.goods[i]!

=null){

if(this.goods[i].getName().indexOf(keyWord)!

=-1){

g[f]=this.goods[i];

f++;

}

}

}

returng;

}

}

publicclassLake{

publicstaticvoidmain(Stringargs[]){

ShopCarsc=newShopCar(6);

sc.add(newBooks("疯狂JAVA",69.9f,1,"李刚","清华大学出版社"));

sc.add(newBooks("疯狂AJAX",79.9f,5,"李刚","电子工业出版社"));

sc.add(newBooks("Oracle实战",99.9f,3,"李兴华","清华大学出版社"));

sc.add(newCloths("T恤",109.9f,2,"李宁","男式,M"));

sc.add(newCloths("牛仔裤",169.9f,2,"森马","女士,L"));

sc.add(newCloths("衬衫",129.9f,1,"杰克琼斯","男式,L"));

System.out.println("==========已买到的商品清单============");

print1(sc.getContent());

System.out.println("==========查询商品详细信息=============");

try

{

print(sc.search(args[0]));

}

catch(Exceptione){

System.out.println("未输入要查询商品或输入错误,"+

"格式为:

\njavaTest商品名(或商品名中的任意字符)");

}

}

publicstaticvoidprint1(Goodsgoods[]){

for(inti=0;i

System.out.println(goods[i].getInfo1());

}

}

publicstaticvoidprint(Goodsgoods[]){

for(inti=0;i

System.out.println(goods[i].getInfo());

}

}

}

第九章:

实例设计:

设计一个生产电脑和搬运电脑类,要求生产出一台电脑就搬走一台电脑,如果没有新的电脑产生,则等待新的电脑产生才能搬运,如果电脑没有搬走,则不能生产新的电脑,最后统计生产出来的电脑的数量。

packagelake;

classComputer{

privateintcount=0;

privateStringname=null;

privateStringstyle=null;

privatebooleanflag=false;

publicvoidsetName(Stringname){

this.name=name;

}

publicvoidsetStyle(Stringstyle){

this.style=style;

}

publicStringgetName(){

returnthis.name;

}

publicStringgetStyle(){

returnthis.style;

}

publicsynchronizedvoidset(Stringname,Stringstyle){

if(flag){

try{

super.wait();

}catch(Exceptione){

e.printStackTrace();

}

}

this.setName(name);

try{

Thread.sleep(100);

}catch(Exceptione){

e.printStackTrace();

}

this.setStyle(style);

System.out.println(Thread.currentThread().getName()

+this.getName()+this.getStyle());

flag=true;

super.notify();

}

publicsynchronizedvoidget(){

if(!

flag){

try{

super.wait();

}catch(Exceptione){

e.printStackTrace();

}

}

try{

Thread.sleep(500);

}catch(Exceptione){

e.printStackTrace();

}

System.out.println(Thread.currentThread().getName()+

this.getName()+this.getStyle());

flag=false;

super.notify();

count++;

}

publicvoidsay(){

System.out.println("货取完了,总计:

"+count+"台!

");

}

}

classMadeimplementsRunnable{

privateComputercomputer=null;

publicMade(Computercomputer){

puter=computer;

}

publicvoidrun(){

booleanflag=false;

for(inti=1;i<51;i++){

if(flag){

puter.set("笔记本",",型号:

L-7");

flag=false;

}else{

puter.set("平板电脑",",型号:

K-4");

flag=true;

}

}

}

}

classMoveimplementsRunnable{

privateComputercomputer=null;

publicMove(Computercomputer){

puter=computer;

}

publicvoidrun(){

for(inti=50;i>-1;i--){

try{

Thread.sleep(100);

}catch(Exceptione){

e.printStackTrace();

}

if(i>0){

puter.get();

}else{

puter.say();

}

}

}

}

publicclassLake{

publicstaticvoidmain(Stringargs[]){

Computerc=newComputer();

Madema=newMade(c);

Movemo=newMove(c);

newThread(ma,"生产部生产出:

").start();

newThread(mo,"物流取走:

").start();

}

}

第十章:

实例设计:

按照要求定义一个操作类,要求完成一个一维数组操作类,其中可以加入任意类型的数据,数据的具体操作类型由程序外部决定,并可以实现查询功能。

第十一章:

第一题:

定义一个StringBuffer类对象,然后通过append()方法向对象中添加26个小写字母,要求每次只能添加一个,共添加26次,然后按照逆序的方式输出,并可以删除前5个字符

第三题:

输入一个Email地址,然后使用正则表达式判断其是否正确。

第五题:

编写正则表达式,判断给定的是否是一个合法的IP地址

第六题:

给定下面的HTML代码:

,要求对内容进行拆分,拆分之后的结果是:

faceArial,Serif

size+2

colorred

第七题:

编写程序,实现国际化应用,从命令行输入国家的代号,如:

1表示中国,2表示美国,3表示法国。

然后根据输入的代号不同调用不同的文件资源显示信息。

另外需要注意的是:

需要在*.calss文件所在位置配上各国的属性文件

第八题:

参照《java实战经典》383页。

第十二章:

第七题:

完成登录系统,从命令行输入用户名和密码,当没有输入用户名或密码的时候提醒输入用户名和密码,让用户继续输入,若正确则显示登录成功信息,失败则显示登录失败信息,如果连续3次输入密码错误则退出系统。

importjava.util.Scanner;

classOperate{

publicvoidcheck(){

Scanners=newScanner(System.in);

booleanflag=true;

intcount=0;

intnum=0;

while(flag){

System.out.print("请输入用户名:

");

Stringstr=s.next();

if(str==null){

System.out.println("用户名不能为空!

");

flag=true;

}else{

if(str.equals("lake")){

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 商务科技

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1