Java语言程序设计郑莉第七章课后习题答案Word下载.docx

上传人:b****3 文档编号:15827405 上传时间:2022-11-16 格式:DOCX 页数:14 大小:85.55KB
下载 相关 举报
Java语言程序设计郑莉第七章课后习题答案Word下载.docx_第1页
第1页 / 共14页
Java语言程序设计郑莉第七章课后习题答案Word下载.docx_第2页
第2页 / 共14页
Java语言程序设计郑莉第七章课后习题答案Word下载.docx_第3页
第3页 / 共14页
Java语言程序设计郑莉第七章课后习题答案Word下载.docx_第4页
第4页 / 共14页
Java语言程序设计郑莉第七章课后习题答案Word下载.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

Java语言程序设计郑莉第七章课后习题答案Word下载.docx

《Java语言程序设计郑莉第七章课后习题答案Word下载.docx》由会员分享,可在线阅读,更多相关《Java语言程序设计郑莉第七章课后习题答案Word下载.docx(14页珍藏版)》请在冰豆网上搜索。

Java语言程序设计郑莉第七章课后习题答案Word下载.docx

重复以上过程,直到找到满足条件的记录,使查找成功,或直到子表不存在为止,此时查找不成功。

5.声明一个类People,成员变量有姓名、出生日期、性别、身高、体重等;

生成10个People类对象,并放在一个以为数组中,编写方法按身高进行排序。

//People类

publicclassPeople{

privateStringname;

privateStringbirthdaydate;

privateStringsex;

privatedoubleheight;

privatedoubleweight;

publicPeople(){//默认构造函数

}

publicPeople(Peoplep){

this.name=p.name;

this.birthdaydate=p.birthdaydate;

this.sex=p.sex;

this.height=p.height;

this.weight=p.weight;

publicPeople(Stringname,Stringbirthdaydate,Stringsex,doubleheight,doubleweight){

this.name=name;

this.birthdaydate=birthdaydate;

this.sex=sex;

this.height=height;

this.weight=weight;

publicStringgetName(){

returnname;

publicvoidsetName(Stringname){

this.name=name;

publicStringgetBirthdaydate(){

returnbirthdaydate;

publicvoidsetBirthdaydate(Stringbirthdaydate){

this.birthdaydate=birthdaydate;

publicStringgetSex(){

returnsex;

publicvoidsetSex(Stringsex){

this.sex=sex;

publicdoublegetHeight(){

returnheight;

publicvoidsetHeight(doubleheight){

this.height=height;

publicdoublegetWeight(){

returnweight;

publicvoidsetWeight(doubleweight){

this.weight=weight;

publicStringtoString(){

return"

姓名:

"

+name+"

\n出生年月:

+birthdaydate+"

\n性别:

+sex+"

\n身高:

+height+"

\n体重:

+weight;

}

//test7_5类

publicclasstest7_5{

/**

*@paramargs

*/

publicstaticvoidmain(String[]args){

//TODOAuto-generatedmethodstub

People[]people={

newPeople("

林楚金"

"

1989年8月13日"

男"

182,63.5),

诸葛亮"

181年7月23日"

184,76.6),

迈克杰克逊"

1958年8月29日"

180,60),

乔丹"

1963年2月17日"

198,98.1),

拿破仑"

1769年8月15日"

159.5,63),

苍井空"

1983年11月11日"

女"

155,45),};

Peopletemp=newPeople();

for(inti=0;

i<

people.length-1;

i++)

for(intj=i+1;

j<

people.length;

j++){

if(people[i].getHeight()<

people[j].getHeight()){

temp=people[j];

people[j]=people[i];

people[i]=temp;

}

System.out.println("

按身高从小到大排序后的结果如下:

);

System.out.println(people[i]+"

\n"

运行结果:

 

6.声明一个类,此类使用私有的ArrayList来存储对象。

使用一个Class类的引用得到第一个对象的类型之后,只允许用户插入这种类型的对象。

//Fuck类

importjava.util.ArrayList;

publicclassFuck{

privateArrayListman=newArrayList();

privateClassclassType=null;

publicvoidadd(Objectf){

if(man.size()==0){

classType=f.getClass();

if(classType.equals(f.getClass())){

man.add(f);

插入成功."

else{

System.out.println("

只允许插入"

+getClassType()+"

类的对象."

publicArrayListgetMan(){

returnman;

publicClassgetClassType(){

returnclassType;

publicFuck(){}

//test7_6

publicclasstest7_6{

Fuckfuckman=newFuck();

Strings=newString("

fuckman.add(s);

fuckman.add(10);

//测试插入插入整数

fuckman.add('

f'

//测试插入插入字符

fuckman.add("

希特勒"

System.out.println(fuckman.getMan());

7.找出一个二维数组的鞍点,即该位置上的元素在所在行上最大,在所在列上最小。

(也可能没有鞍点)

//test7_7

importjava.util.Scanner;

publicclasstest7_7{

publicstaticvoidmain(String[]args){

introw,series,max;

booleanT=false;

Scannercin=newScanner(System.in);

请输入数组的行数"

row=cin.nextInt();

请输入数组的列数"

series=cin.nextInt();

int[][]Array=newint[row][series];

int[]R=newint[row];

//记录每行最大的数的列标

int[]S=newint[series];

//记录每列最小的数的行标

请输入数组内容"

for(inti=0;

i<

Array.length;

i++)

for(intj=0;

j<

Array[i].length;

j++)

{Array[i][j]=cin.nextInt();

if(j==series-1){

max=Array[i][0];

for(intz=1;

z<

series;

z++)

if(Array[i][z]>

max)

{

max=Array[i][z];

R[i]=z;

Array[0].length;

max=Array[0][j];

row;

if(Array[z][j]<

max=Array[z][j];

S[j]=z;

Array.length;

if(S[R[i]]==i)

鞍点:

+"

Array["

+i+"

]["

+R[i]+

"

]:

+Array[i][R[i]]+"

T=true;

if(T==false)

没有鞍点"

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

当前位置:首页 > 法律文书 > 调解书

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

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