JAVA编程思想课后习题答案资料Word文档下载推荐.docx

上传人:b****4 文档编号:17797415 上传时间:2022-12-10 格式:DOCX 页数:14 大小:16.81KB
下载 相关 举报
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

}

}

ATypeNamea=newATypeName();

a.i=3;

a.d=2.71828;

a.b=false;

a.show();

练习4:

publicclassDataOnlyTest{

classDataOnly{

DataOnlydata=newDataOnly();

data.i=3;

data.d=2.71828;

data.b=false;

data.show();

练习5:

publicclassDOTest2{

data.i=234;

data.d=2.1234545;

data.b=true;

练习6:

publicclassStorageTest{

classStoreStuff{

intstorage(Strings){

returns.length()*2;

}

}

StoreStuffx=newStoreStuff();

System.out.println(x.storage("

hi"

));

练习7:

classStaticTest{

staticinti=47;

classIncrementable{

staticvoidincrement(){StaticTest.i++;

publicclassITest{

System.out.println("

StaticTest.i="

+StaticTest.i);

StaticTestst1=newStaticTest();

StaticTestst2=newStaticTest();

st1.i="

+st1.i);

st2.i="

+st2.i);

Incrementablesf=newIncrementable();

sf.increment();

Aftersf.increment()called:

"

st1.i="

st2.i="

Incrementable.increment();

AfterIncrementable.incrementcalled:

练习8:

publicclassOneStaticTest{

StaticTestst1=newStaticTest();

StaticTestst2=newStaticTest();

Incrementable.increment();

AfterIncrementable.increment()called:

st1.i=3;

Afterst1.i=3,"

CreateanotherStaticTest,st3."

StaticTestst3=newStaticTest();

st3.i="

+st3.i);

练习9:

publicclassAutoboxTest{

booleanb=false;

charc='

x'

;

bytet=8;

shorts=16;

inti=32;

longl=64;

floatf=0.32f;

doubled=0.64;

BooleanB=b;

booleanb="

+b);

BooleanB="

+B);

CharacterC=c;

charc="

CharacterC="

+C);

ByteT=t;

bytet="

+t);

ByteT="

+T);

ShortS=s;

shorts="

+s);

ShortS="

+S);

IntegerI=i;

inti="

IntegerI="

+I);

LongL=l;

longl="

+l);

LongL="

+L);

FloatF=f;

floatf="

+f);

FloatF="

+F);

DoubleD=d;

doubled="

+d);

DoubleD="

+D);

练习10:

publicclassCommandArgTest{

args[0]="

+args[0]);

args[1]="

+args[1]);

args[2]="

+args[2]);

练习11:

publicclassRainbow{

AllTheColorsOfTheRainbowatc=newAllTheColorsOfTheRainbow();

atc.anIntegerRepresentingColors="

+atc.anIntegerRepresentingColors);

atc.changeColor(7);

atc.changeTheHueOfTheColor(77);

Aftercolorchange,atc.anIntegerRepresentingColors="

atc.hue="

+atc.hue);

classAllTheColorsOfTheRainbow{

intanIntegerRepresentingColors=0;

inthue=0;

voidchangeTheHueOfTheColor(intnewHue){

hue=newHue;

intchangeColor(intnewColor){

returnanIntegerRepresentingColors=newColor;

练习12:

publicclassDocTest{

/**Entrypoingtoclass&

application.

*@paramargsarrayofstringarguments

*@throwsexceptionsNoexceptionsthrown

*/

Hello,it'

s:

System.out.println(newDate());

练习13-1:

publicclassDocumentation1{

/**Afieldcomment*/

publicinti;

/**Amethodcomment*/

publicvoidf(){}

2:

publicclassDocumentation2{

Dated=newDate();

voidshowDate(){

Date="

3:

publicclassDocumentation3{

Dated=newDate();

d="

练习14:

publicclassDocumentation4{

publicinti=2;

privateintj=3;

publicstaticvoidmain(String[]args){

Dated=newDate();

练习15:

publicclassHelloDocTest{

练习16:

classTree{

intheight;

Tree(){

Plantingaseedling"

height=0;

Tree(intinitialHeight){

height=initialHeight;

Creatingnewtreethatis"

+height+"

feettall"

voidinfo(){

Treeis"

voidinfo(Strings){

System.out.println(s+"

:

Treeis"

 

publicclassOverloading{

for(inti=0;

i<

5;

i++){

Treet=newTree(i);

t.info();

t.info("

overloadingmethod"

//Overloadedconstructor:

newTree();

第三章

publicclassPrintTest{

print("

Hello,fromshortform."

P.rintln("

Hellofromgreggordonform."

Hellofromlongform."

classTube{

floatlevel;

publicclassAssign{

Tubet1=newTube();

Tubet2=newTube();

t1.level=0.9f;

t2.level=0.47f;

1:

t1.level:

+t1.level+"

t2.level:

+t2.level);

t1=t2;

2:

t1.level=0.27f;

3:

classBox{

floata;

publicclassPassObject2{

staticvoidf(Boxy){

y.a=2.71828f;

Boxx=newBox();

x.a=3.1416f;

x.a="

+x.a);

f(x);

classVelocityCalculator{

staticfloatvelocity(floatd,floatt){

if(t==0)return0f;

elsereturnd/t;

}

publicclassVelocityTester{

floatd=565.3f;

floatt=3.6f;

Distance:

Time:

floatv=VelocityCalculator.velocity(d,t);

Velocity:

+v);

classDog{

Stringname;

Stringsays;

voidsetName(Stringn){

name=n;

voidsetSays(Strings){

says=s;

voidshowName(){

P.rintln(name);

voidspeak(){

P.rintln(says);

publicclassDogTest{

Dogspot=newDog();

spot.setName("

Spot"

spot.setSays("

Ruff!

Dogscruffy=newDog();

scruffy.setName("

Scruffy"

scruffy.setSays("

Wurf!

spot.showName();

spot.speak();

scruffy.showName();

scruffy.speak();

publicclassDogCompare{

Dogbutch=newDog();

butch.setName("

Butch"

butch.setSays("

Hello!

butch.showName();

butch.speak();

Comparison:

spot==butch:

+(spot==butch));

spot.equals(butch):

+spot.equals(butch));

butch.equals(spot):

+butch.equals(spot));

Nowassign:

spot=butch"

spot=butch;

Compareagain:

+(spot==

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

当前位置:首页 > 小学教育 > 学科竞赛

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

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